2010-07-15 118 views
0

我創建了一個滾動視圖,並且在此滾動視圖上放置了一些按鈕。滾動視圖透明,alpha = 0.5。事實上,即使我的按鈕設置爲1的alpha,並且它們的不透明度設置爲YES,我的按鈕也是透明的。我知道我添加了任何子視圖到任何超視圖視圖,那麼超視圖的屬性應該適用於它的子視圖。但我希望所有按鈕都放在透明滾動視圖上不透明。 請給我一些建議。你能否展示子視圖如何不繼承SupperView的屬性? 謝謝你的回覆。透明滾動視圖上的非透明按鈕有問題

[i]- (void)viewDidLoad { 
    [super viewDidLoad]; 
    DefaultLayoutData = [[Database GetDefaultLayout] retain]; 
    scrollView.contentSize = CGSizeMake(SCREEN_SIZE_WIDTH,480*4); 
    scrollView.pagingEnabled = YES; 
    scrollView.scrollEnabled = YES; 
    //scrollView. 
    scrollView.showsHorizontalScrollIndicator = YES; 
    scrollView.showsVerticalScrollIndicator = YES; 
    scrollView.scrollsToTop = YES; 
    scrollView.delegate = self; 
    [scrollView setAlpha:0.5]; 
    for (int i=0; i<[DefaultLayoutData count]; i++) { 
     NSMutableArray *BtnEntryData = [DefaultLayoutData objectAtIndex:i]; 
     MyUIButton* buttonCustom = [MyUIButton buttonWithType:UIButtonTypeCustom]; 

     buttonCustom.frame = CGRectMake([[BtnEntryData objectAtIndex:2] intValue],  [[BtnEntryData objectAtIndex:3] intValue], [[BtnEntryData objectAtIndex:5] intValue],  [[BtnEntryData objectAtIndex:4] intValue]); 
     [buttonCustom setImage:[UIImage imageNamed:[BtnEntryData objectAtIndex:1] ] forState:UIControlStateNormal]; 
     [buttonCustom setImage:[UIImage imageNamed:[[BtnEntryData objectAtIndex:1] stringByAppendingString:@"1"]] forState:UIControlStateHighlighted]; 
     [buttonCustom setAlpha:1.0]; 
     buttonCustom.alpha = 1.0; 
     [buttonCustom setOpaque:YES]; 
     [buttonCustom setBackgroundColor:[UIColor redColor]]; 
     [buttonCustom setClearsContextBeforeDrawing:TRUE]; 

     [scrollView addSubview:buttonCustom]; 
    [scrollView setBackgroundColor:[UIColor redColor]]; 
    buttonCustom.scrollView = scrollView; 
    ButtonArray = [buttonCustom retain]; 
    } 
} 

回答

0

你真的需要你的滾動視圖是半透明的嗎?可能只是爲它設置適當的背景顏色?類似於:

[scrollView setBackgroundColor:[UIColor colorWithWhite:1.0f alpha:0.5f]]; 
+0

scrollview後面有一個視圖,它包含背景圖像,我的客戶希望按鈕放置在透明的srollview上,並且他們希望以下視圖的背景可見。 ---- UIView(它包含背景圖像) ----------- UIScrollview ----------(透明與alpha == 0.5) ------ ------------- UIButton(alpha === 1,視圖的背景是可見的。) 謝謝你的回覆。 – becktoan 2010-07-15 09:22:43

+0

然後設置scrollview的透明背景顏色必須做你想要的 – Vladimir 2010-07-15 09:35:01