Ami*_*Raj 4 uicolor swift uialertcontroller
我想在swift中更改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")
})
Run Code Online (Sandbox Code Playgroud)
我想在上面的警告框中更改无效名称的颜色.
pbu*_*h25 17
您可以使用它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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7534 次 |
| 最近记录: |