在UIAlertController

时间:2016-04-16 09:06:03

标签: ios objective-c swift uialertcontroller

我有两个按钮,但我只想将一个改为红色。当我使用下面的功能时 它将全部更改为红色。我只想改变一个按钮的颜色。我该怎么办?

alertController.view.tintColor = UIColor.redColor()

4 个答案:

答案 0 :(得分:7)

    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")

答案 1 :(得分:3)

设置UIAlertActionStyle.Destructive





检查此链接





UIAlertController自定义字体,大小,颜色




答案 2 :(得分:3)

你可以试试这个,

deleteAction.setValue(color, forKey: titleTextColor)

对我有用!

答案 3 :(得分:2)

<强>夫特

您需要将UIAlertActionStyle.Destructive用于红色的按钮文字颜色

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)

<强>目标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];

输出

enter image description here

有关其他信息,请参阅this