How do I change the UIAlertController's Title font using Swift?
I'm not talking about the message color, I'm not talking about the buttons color.
I'm talking about the Title.
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)
Added the correct line of code to my answer as it's much more concise than the answer below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With