在UIAlertController中更改标题颜色

我有两个按钮,但我只想将一个更改为红色。当我使用下面的function时
它变成了红色 。 我只想改变一个按钮的颜色。 我该怎么做?

alertController.view.tintColor = UIColor.redColor() 

只有红色设置UIAlertActionStyle.Destructive时可以使用颜色

检查此链接

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

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

迅速

你需要使用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) 

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]; 

产量

在此处输入图像描述

有关其他信息,请参阅此

你可以试试这个,

 deleteAction.setValue(color, forKey: titleTextColor) 

这个对我有用!