I wanna set special color for title and message of UIAlertController, and refer to the before question , now font-size can be changed but color cannot
below is my extension, it seems background color can work, but i cannot see anything in it.
extension UIAlertController {
func applyTitleMessageStyle() {
let titleParagraphStyle = NSMutableParagraphStyle()
titleParagraphStyle.alignment = .center
let alertController: UIAlertController = self
if alertController.title != nil {
let attributedTitle = NSAttributedString(string: alertController.title!, attributes: [
.foregroundColor: UIColor.red, //William don't work
//.backgroundColor: UIColor.black, // just a black rectangular
.font: UIFont.systemFont(ofSize: 30),
.paragraphStyle: titleParagraphStyle //William
])
alertController.setValue(attributedTitle, forKey: "attributedTitle")
}
if alertController.message != nil {
let attributedMessage = NSAttributedString(string: alertController.message!, attributes: [
.foregroundColor: UIColor.red, //William don't work
//.backgroundColor: UIColor.black, //just a black rectangular
.font: UIFont.systemFont(ofSize: 25),
.paragraphStyle: titleParagraphStyle //William
])
alertController.setValue(attributedMessage, forKey: "attributedMessage")
}
}
The screenshot is as follows
New contributor
William Wang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.