#ios #swift #xcode #ios13 #uialertcontroller
#iOS #swift #xcode #ios13 #uialertcontroller
Вопрос:
Как я могу изменить цвет заголовка UIAlertController для версии iOS выше 12?
Приведенный ниже код работает только для версии ios ниже 13 :-
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)
Комментарии:
1. он отлично работает для меня в ios 14.3
2. Я бы не стал использовать этот код, поскольку он использует частные свойства. Завтра он может не работать и даже выйти из строя. Будь осторожен с этим.