Ho una sottoview che è stata aggiunta al mio UIView. L'idea è che la sottoview sia un pannello in bilico con uibuttons. La sottoview ha un alfa di 0.2, in quanto l'utente deve essere in grado di vedere cosa c'è dietro.iPhone SDK: subviews non trasparenti in visualizzazione trasparente
Il problema è che quando aggiungo gli uibutton alla sottoview, ereditano l'alpha dalla sottoview (voglio che i pulsanti siano non trasparenti e abbiano un alfa di 1.0). Ho provato ad affrontare questo problema iterando attraverso gli uibutton e impostando il loro alpha su 1.0 senza successo. Soluzioni?
// 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;
}
Saluti, buona soluzione. –
Grazie Philippe, stavo cercando di fare una cosa simile, tranne attraverso l'IB e non ero in grado di ottenere l'effetto che volevo. Ma la tua soluzione mi ha aiutato a farcela. – sherry