我有两个按钮,但我只想将一个改为红色。当我使用下面的功能时 它将全部更改为红色。我只想改变一个按钮的颜色。我该怎么办?
alertController.view.tintColor = UIColor.redColor()
答案 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)
答案 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];
输出
有关其他信息,请参阅this