如何使用 Swift 更改 UIAlertController 的标题字体?
我不是在谈论消息颜色,我不是在谈论按钮颜色。
我说的是标题。
最佳答案
let attributedString = NSAttributedString(string: "Title", attributes: [
NSFontAttributeName : UIFont.systemFontOfSize(15), //your font here
NSForegroundColorAttributeName : UIColor.redColor()
])
let alert = UIAlertController(title: "", message: "", preferredStyle: .alert)
alert.setValue(attributedString, forKey: "attributedTitle")
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (_) in
}
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)
在我的答案中添加了正确的代码行,因为它比下面的答案简洁得多。
关于ios - Swift 如何更改 UIAlertController 的标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31662591/