我想快速更改 UIAlertController 中消息的颜色。默认是黑色我想把它改成红色。
我的 UIAlertController 如下所示:
alert = UIAlertController(title: "", message: "Invalid Name", preferredStyle: UIAlertControllerStyle.Alert)
alert.view.tintColor = UIColor.blackColor()
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
}))
self.presentViewController(alert, animated: true, completion: {
println("completion block")
})
我想更改上面警告框中无效名称的颜色。
最佳答案
您可以使用attributedStrings
创建您想要的颜色、字体、大小和样式,然后将字符串设置为标题。
编辑:更新了示例
let attributedString = NSAttributedString(string: "Invalid Name", attributes: [
NSParagraphStyleAttributeName: paragraphStyle,
NSFontAttributeName : UIFont.systemFontOfSize(15),
NSForegroundColorAttributeName : UIColor.redColor()
])
let alert = UIAlertController(title: "Title", message: "", preferredStyle: .Alert)
alert.setValue(attributedString, forKey: "attributedMessage")
let cancelAction = UIAlertAction(title: "Cancel",
style: .Default) { (action: UIAlertAction!) -> Void in
}
presentViewController(alert,
animated: true,
completion: nil)
关于swift - 在 Swift 中更改消息 UIAlertController 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31296457/