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 tal
Here is for Swift 4 ++ also using a global instance for UIAlert
func showAlertError(withTitle title: String, withMessage message: String) {
var dialogTitle = title
if dialogTitle.isEmpty { dialogTitle = "Error:" }
let attributedString = NSAttributedString(string: dialogTitle, attributes: [
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15),
NSAttributedString.Key.foregroundColor : UIColor.red
])
let alert = UIAlertController(title: "", message: message, preferredStyle: .alert)
alert.setValue(attributedString, forKey: "attributedTitle")
let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(ok)
DispatchQueue.main.async(execute: {
self.present(alert, animated: true)
})
}