Ios 更改UIAlertController中的标题颜色
我有两个按钮,但我只想将一个按钮更改为红色。当我使用下面的功能时Ios 更改UIAlertController中的标题颜色,ios,objective-c,swift,uialertcontroller,Ios,Objective C,Swift,Uialertcontroller,我有两个按钮,但我只想将一个按钮更改为红色。当我使用下面的功能时 它将全部变为红色。我只想改变一个按钮的颜色。我怎么做 alertController.view.tintColor = UIColor.redColor() Swift 对于红色按钮文本颜色,您需要使用UIAlertActionStyle.destromical let alert = UIAlertController( title: "Basic alert style", message: "Bas
它将全部变为红色。我只想改变一个按钮的颜色。我怎么做
alertController.view.tintColor = UIColor.redColor()
Swift
对于红色按钮文本颜色,您需要使用UIAlertActionStyle.destromical
let alert = UIAlertController(
title: "Basic alert style",
message: "Basic alert With buttons",
preferredStyle: .alert )
let Reset = UIAlertAction(
title: "Reset",
style: .destructive) { (action) in
// do your stuff
}
let Cancel = UIAlertAction(
title: "Cancel", style: .default) { (action) in
// do your stuff
}
alert.addAction(Reset)
alert.addAction(Cancel)
present(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];
输出
有关更多信息,请参见设置UIAlertActionStyle.Destructive时,只能使用红色 检查此链接 你可以试试这个
deleteAction.setValue(color, forKey: titleTextColor)
这对我有用 这是最好的答案!效果很好
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")