如何在 UIAlertController 中以编程方式更改特定按钮文本颜色
How to change the specific button text colour programmatically in the UIAlertController
我想将 UIAlertController 中 "Cancel" 按钮的颜色更改为橙色,并保持 "Log Out" 按钮的颜色不变。我在下面附上了警报控制器的屏幕截图和代码。
警报视图代码
alert = UIAlertController(title: "", message: "Are you sure you want to log out?", preferredStyle: UIAlertControllerStyle.Alert)
alert.view.tintColor = UIColor.blackColor()
alert.addAction(UIAlertAction(title: "Log out", style: UIAlertActionStyle.Cancel, handler:{ (UIAlertAction)in
println("Log Out button clicked.")
prefs.setBool(false, forKey: "Isloggedin")
NSUserDefaults.resetStandardUserDefaults()
prefs.setBool(true, forKey: "IsEmail")
prefs.setObject(email, forKey: "loggedemail")
prefs.synchronize()
let mainview = self.storyboard?.instantiateViewControllerWithIdentifier("mainscreen") as! mainViewController
self.navigationController?.pushViewController(mainview, animated: true)
}))
//alert.view.tintColor = UIColor.yellowColor()
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
println("Cancel button clicked.")
}))
self.presentViewController(alert, animated: true, completion: {
println("completion block.")
})
我已经创建了一个自定义提醒,我们可以根据需要在其中进行更改。
我附上了 GitHub Link
我想将 UIAlertController 中 "Cancel" 按钮的颜色更改为橙色,并保持 "Log Out" 按钮的颜色不变。我在下面附上了警报控制器的屏幕截图和代码。
警报视图代码
alert = UIAlertController(title: "", message: "Are you sure you want to log out?", preferredStyle: UIAlertControllerStyle.Alert)
alert.view.tintColor = UIColor.blackColor()
alert.addAction(UIAlertAction(title: "Log out", style: UIAlertActionStyle.Cancel, handler:{ (UIAlertAction)in
println("Log Out button clicked.")
prefs.setBool(false, forKey: "Isloggedin")
NSUserDefaults.resetStandardUserDefaults()
prefs.setBool(true, forKey: "IsEmail")
prefs.setObject(email, forKey: "loggedemail")
prefs.synchronize()
let mainview = self.storyboard?.instantiateViewControllerWithIdentifier("mainscreen") as! mainViewController
self.navigationController?.pushViewController(mainview, animated: true)
}))
//alert.view.tintColor = UIColor.yellowColor()
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
println("Cancel button clicked.")
}))
self.presentViewController(alert, animated: true, completion: {
println("completion block.")
})
我已经创建了一个自定义提醒,我们可以根据需要在其中进行更改。
我附上了 GitHub Link