Я новичок в разработке iOS.
Я пытаюсь изменить заголовок и цвет сообщения UIAlertController, но не работает, цвет не меняется.
Вот мой код:
let alert = UIAlertController(title: NSLocalizedString(«notifications_popup2_title», comment: «»), message: NSLocalizedString(«notifications_popup2_message», comment: «»), preferredStyle: UIAlertControllerStyle.actionSheet) // Change font of the title and message let titleFont:[NSAttributedStringKey : AnyObject] = [ NSAttributedStringKey(rawValue: NSAttributedStringKey.font.rawValue) : UIFont(name: «Flama-Basic», size: 22)!, NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue) : UIColor(hexString: «#2e2e2e»)! ] let messageFont:[NSAttributedStringKey : AnyObject] = [ NSAttributedStringKey(rawValue: NSAttributedStringKey.font.rawValue) : UIFont(name: «Flama-light», size: 18)!, NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue) : UIColor(hexString: «#2e2e2e»)! ] let attributedTitle = NSMutableAttributedString(string: NSLocalizedString(«notifications_popup2_title», comment: «»), attributes: titleFont) let attributedMessage = NSMutableAttributedString(string: NSLocalizedString(«notifications_popup2_message», comment: «»), attributes: messageFont) alert.setValue(attributedTitle, forKey: «attributedTitle») alert.setValue(attributedMessage, forKey: «attributedMessage»)
Если я изменю стиль оповещения на .alert, он работает …
Добро пожаловать в SO! Пожалуйста, объясните, что вы имеете в виду, но не работает. Также прочтите Как задать вопрос. — person noquart3r schedule 29.11.2019
Выкладываю скриншот. Я думаю не определяет цвет — person noquart3r schedule 29.11.2019
Заголовок / сообщение UIAlertController принимает строковое свойство, а не строку с атрибутами, поэтому я ожидал, что они не сработают. Я предполагаю, что это работает для предупреждения по причинам совместимости с устаревшими версиями. — person noquart3r schedule 29.11.2019
Не надо. Это использует частные свойства / библиотеки, это может измениться, как это было (например, между iOS 12 и iOS13), и поэтому больше не будет работать, и когда-нибудь может быть причиной Apple отклонить приложение. Вместо этого создайте свой собственный. — person noquart3r schedule 29.11.2019
Ср. stackoverflow.com/questions/58224830/ — person noquart3r schedule 29.11.2019
Источник: