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
I construct this class:
class Alert {
class func showAlert(title: String, titleColor: UIColor, message: String, preferredStyle: UIAlertControllerStyle, titleAction: String, actionStyle: UIAlertActionStyle, vc: UIViewController) {
let attributedString = NSAttributedString(string: title, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 16), NSAttributedStringKey.foregroundColor: titleColor])
let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
alert.setValue(attributedString, forKey: "attributedTitle")
alert.addAction(UIAlertAction(title: titleAction, style: actionStyle, handler: nil))
vc.present(alert, animated: true)
}
}
Usage
Alert.showAlert(title: "yourTitle", titleColor: .yourcolor, message: "your message", preferredStyle: .alert, titleAction: "your title action", actionStyle: .yourActionStyle, vc: self)
Hope this help :)