2009-09-11 16 views
11

UIView'ime eklenen bir alt görüm var. Buradaki fikir, alt görüntünün, uibuttons ile gezinen bir panel olmasıdır. Alt görüşe, kullanıcının arkasında ne olduğunu görebilmesi için 0,2 alfa verilir.iPhone SDK: Saydam görünümde şeffaf olmayan alt görünümler

Sorun, alt görünüme uibuttons eklediğimde alt görünümü alfadan aldıklarıdır (düğmelerin saydam olmamasını ve 1.0 değerine sahip olmasını istiyorum). Uibuttons'u yineleyerek ve alfalarını sıfırdan 1.0'a başarılı bir şekilde ayarlayarak bu sorunu çözmeye çalıştım. Çözümler?

// Create the subview and add it to the view 
    topHoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
    topHoverView.backgroundColor = [UIColor blackColor]; 
    [topHoverView setAlpha:0.2]; 
    [self.view addSubview:topHoverView]; 

    // Add button 1 
    button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button1 setFrame:CGRectMake(20, 10, 80, 30)]; 
    [button1 setTitle:@"New" forState:UIControlStateNormal]; 
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside]; 
    [topHoverView addSubview:button1]; 

    // Add button 2 
    button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button2 setFrame:CGRectMake(120, 10, 80, 30)]; 
    [button2 setTitle:@"Clear" forState:UIControlStateNormal]; 
    [button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside]; 
    [topHoverView addSubview:button2]; 

    // Add button 3 
    button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [button3 setFrame:CGRectMake(220, 10, 80, 30)]; 
    [button3 setTitle:@"Delete" forState:UIControlStateNormal]; 
    [button3 addTarget:self action:@selector(button3Action:) forControlEvents:UIControlEventTouchUpInside]; 
    [topHoverView addSubview:d button3]; 

    // Attempt to iterate through the subviews (buttons) to set their transparency back to 1.0 
    for (UIView *subView in topHoverView.subviews) { 
     subView.alpha = 1.0; 
    } 

cevap

15

alpha 1.0 ve saydam bir arka plan rengiyle topHoverView oluşturmalısınız. Sonra alfa 0,2 ile tam bir görünümünü kapsayan siyah bir arka plana sahip bir subview ekleyin ve sonra topHoverView için düğmeler ekleyin:

// Create the subview and add it to the view 
topHoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
topHoverView.backgroundColor = [UIColor transparentColor]; 
[topHoverView setAlpha:1.0]; 
[self.view addSubview:topHoverView]; 

canvasView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
canvasView.backgroundColor = [UIColor blackColor]; 
[canvasViewView setAlpha:0.2]; 
[topHoverView.view addSubview:canvasView]; 

// Add button 1 
button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button1 setFrame:CGRectMake(20, 10, 80, 30)]; 
[button1 setTitle:@"New" forState:UIControlStateNormal]; 
[button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside]; 
[topHoverView addSubview:button1]; 

// Add button 2 
button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button2 setFrame:CGRectMake(120, 10, 80, 30)]; 
[button2 setTitle:@"Clear" forState:UIControlStateNormal]; 
[button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside]; 
[topHoverView addSubview:button2]; 

// Add button 3 
button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button3 setFrame:CGRectMake(220, 10, 80, 30)]; 
[button3 setTitle:@"Delete" forState:UIControlStateNormal]; 
[button3 addTarget:self action:@selector(button3Action:) forControlEvents:UIControlEventTouchUpInside]; 
[topHoverView addSubview:d button3]; 

// Attempt to iterate through the subviews (buttons) to set their transparency back to 1.0 
for (UIView *subView in topHoverView.subviews) { 
    subView.alpha = 1.0; 
} 
+0

Şerefe, güzel bir çözüm. –

+0

Teşekkürler Philippe, IB dışında benzer bir şey yapmaya çalışıyordum ve istediğim etkiyi elde edemedim. Ama senin geçici çözümüm bana yardımcı oldu. – sherry

6

yerine

topHoverView.backgroundColor = [UIColor transparentColor]; 

arasında, aşağıdaki kod haklı.

topHoverView.backgroundColor = [UIColor clearColor];