2016-04-16 15 views
0

Ich habe zwei Knopf, aber ich möchte nur zu ändern man red.When ich die Funktion unter
alles zu rot ändern verwenden. Ich möchte nur die Farbe von nur einem Knopf ändern. Wie kann ich es tun?ändern Titel Farbe in UIAlertController

alertController.view.tintColor = UIColor.redColor() 

Antwort

2

Swift

Sie UIAlertActionStyle.Destructive für Schaltfläche Textfarbe in rot

let alert = UIAlertController(
title: "Basic Alert style", 
message: "Basic Alert With Buttons", 
preferredStyle: UIAlertControllerStyle.Alert) 

let Reset = UIAlertAction(
title: "Reset", 
style: UIAlertActionStyle.Destructive) { (action) in 
// do your stuff 
} 

let Cancel = UIAlertAction(
title: "Cancel", style: UIAlertActionStyle.Default) { (action) in 
// do your stuff 
} 

alert.addAction(Reset) 
alert.addAction(Cancel) 

presentViewController(alert, animated: true, completion: nil) 

Objective-C

UIAlertController *alert = [UIAlertController 
          alertControllerWithTitle:@"Basic Alert style" 
          message:@"Basic Alert With Buttons" 
          preferredStyle:UIAlertControllerStyleAlert]; 

UIAlertAction *Reset = [UIAlertAction 
     actionWithTitle:NSLocalizedString(@"Reset", @"Reset action") 
        style:UIAlertActionStyleDestructive 
       handler:^(UIAlertAction *action) 
       { 
        NSLog(@"Reset action"); 
       }]; 

UIAlertAction *Cancel = [UIAlertAction 
     actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") 
        style:UIAlertActionStyleDefault 
       handler:^(UIAlertAction *action) 
       { 
        NSLog(@"Cancel action"); 
       }]; 

[alert addAction:Reset]; 
[alert addAction:Cancel]; 
[self presentViewController:alert animated:YES completion:nil]; 

Ausgang verwenden müssen

enter image description here

für weitere Informationen this

0

Sie können versuchen, diesen Satz,

deleteAction.setValue(color, forKey: titleTextColor) 

Es funktioniert für mich!

0
let alertController = UIAlertController(title: title, message: message, preferredStyle: .actionSheet) 

alertController.setValue(NSAttributedString(string: title, attributes: [NSFontAttributeName : UIFont.appFont_OpenSans_Regular(fontSize: 15),NSForegroundColorAttributeName : BLACK_COLOR]), forKey: "attributedTitle") 
alertController.setValue(NSAttributedString(string: message, attributes: [NSFontAttributeName : UIFont.appFont_OpenSans_Regular(fontSize: 13),NSForegroundColorAttributeName : APP_COLOR_BLUE_1]), forKey: "attributedMessage")