12

I am trying to create an UIAlertAction that has black color text for the first button and blue for the second. If I change the tint then all go black but i can't change the first button to black without it. Below is my code:

let alert = UIAlertController(title: "", message: "", preferredStyle: .actionSheet)
// alert.view.tintColor = UIColor.black

alert.addAction(UIAlertAction(title: "First", style: .cancel, handler: nil))

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

self.present(alert, animated: true, completion: nil)
4

2 回答 2

42

我可以通过添加这个或每种颜色来做到这一点

let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler:nil)
                cancelAlert.setValue(UIColor.blue, forKey: "titleTextColor")
                alert.addAction(cancelAlert)
于 2017-03-15T18:13:59.583 回答
2

对于那些在这里只是更改操作按钮颜色的人,您可以更改样式,例如删除按钮的 .破坏性:

 alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler:{(UIAlertAction) in
于 2017-07-22T05:05:47.443 回答