2017-03-14 4 views
1

最初のボタンは黒色のテキスト、2番目のボタンは青色のUIAlertActionを作成しようとしています。私が色合いを変えれば、すべて黒くなりますが、最初のボタンを黒色に変更することはできません。以下は私のコードです:異なる色のボタンテキストを使用した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) 
+0

私は –

+1

色はBAであるなどUIAlertController、すなわち与えられたスタイルを除き、別のボタンのために異なる色を可能と思わ取り消し、デフォルトではありません.scelは黒で、.defaultは黒で、.destructiveは赤です。独自のカスタムUIAlertControllerを作成しない限り、色を変更する方法はありません。 – creeperspeak

答えて

7

私はこのまたは各色だけでアクションボタンの色を変更するためにここにいる人のために

let cancelAlert = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler:nil) 
       cancelAlert.setValue(UIColor.blue, forKey: "titleTextColor") 
       alert.addAction(cancelAlert) 
+0

私はそれを目的Cで使用しましたが、アプリケーションがクラッシュします。客観的なCのための任意の提案? – gEeKyMiNd

+0

私はそれを試していませんが、ここでは客観的なcのためのいくつかの提案がありますhttps://stackoverflow.com/questions/36662233/change-title-color-in-uialertcontroller – user1079052

1

を追加することによってそれを行うことができた、あなたが変更することができます例えばのようなスタイルは、削除ボタン用.destructive:

alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler:{(UIAlertAction) in 
関連する問題