[英]UIAlertAction with different color button text
我正在嘗試創建一個UIAlertAction,第一個按鈕為黑色文本,第二個按鈕為藍色。 如果我改變色調然后全部變黑,但是沒有它我不能將第一個按鈕改為黑色。 以下是我的代碼:
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)
我能夠通過添加這種顏色或每種顏色來實現
let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler:nil)
cancelAlert.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(cancelAlert)
對於那些只是更改動作按鈕顏色的人,您可以更改樣式,例如.destructive for delete button:
alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler:{(UIAlertAction) in
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.