2013-10-06 15 views

risposta

28

Utilizzare il metodo delegato willPresentActionSheet di UIActionSheet per modificare il colore del pulsante del foglio di azione.

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet 
{ 
    for (UIView *subview in actionSheet.subviews) { 
     if ([subview isKindOfClass:[UIButton class]]) { 
      UIButton *button = (UIButton *)subview; 
      button.titleLabel.textColor = [UIColor greenColor]; 
     } 
    } 
} 
+3

Questa risposta è migliore. Utilizza un metodo delegato per non parlare più conciso. Anche la risposta sopra non cambia il colore del pulsante Annulla. – LazerLex

+0

Per qualche motivo, se vuoi anche cambiare il carattere, devi farlo prima di cambiare il colore, altrimenti non funzionerà –

+0

@BrenoGazzola: Cosa succede? –

18

Si potrebbe fare qualcosa di simile:

// Your code to instantiate the UIActionSheet 
UIActionSheet *actionSheet = [[UIActionSheet alloc] init]; 
// Configure actionSheet 

// Iterate through the sub views of the action sheet 
for (id actionSheetSubview in actionSheet.subviews) { 
    // Change the font color if the sub view is a UIButton 
    if ([actionSheetSubview isKindOfClass:[UIButton class]]) { 
     UIButton *button = (UIButton *)actionSheetSubview; 
     [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; 
     [button setTitleColor:[UIColor greenColor] forState:UIControlStateSelected]; 
     [button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted]; 

    } 
} 

Se avete intenzione di riutilizzare questo molto, mi piacerebbe sottoclasse UIActionSheet e utilizzando questo codice.

+0

è che l'utilizzo API private? –

+0

No, si tratta solo di accedere a tutte le sottoview di un UIActionSheet e di trovare i pulsanti – Tim

+1

Quando lo si tocca, torna in blu. –

0

È possibile modificare facilmente il colore della tinta della applicazione che utilizza questo breve la funzione del metodo di didFinishLaunchingWithOptions AppDelegate.

[[UIView appearance] setTintColor:[UIColor redColor]]; 

Spero che vi aiuterà :)

Problemi correlati