UIAlertControllerTitle标题没有响应?

时间:2017-11-30 07:02:03

标签: ios swift uialertcontroller

我的应用程序是响应式的,如果显示警报并且用户增加了字体大小,则警报消息的字体大小会增加,但警报标题的字体大小不会增加。我使用下面的代码来显示UIAlertController。

let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)

//Swift 2.0
let deleteAction = UIAlertAction(title: deleteBtnText, style: UIAlertActionStyle.destructive, handler: deleteHandler)
alert.addAction(deleteAction)

let cancelAction = UIAlertAction(title: cancelBtnText, style: UIAlertActionStyle.cancel, handler: cancelHandler)
alert.addAction(cancelAction)

// Set light teal color for alert tint color
alert.view.tintColor = UIColor.LTColor()
// set background color for text
let dictTitleColor = [NSAttributedStringKey.foregroundColor: UIColor.LTColor()]
let titleAttributedString = NSMutableAttributedString(string: title, attributes: dictTitleColor)
alert.setValue(titleAttributedString, forKey: "attributedTitle")

let appDelegate = UIApplication.shared.delegate as! AppDelegate
UIUtils.stopIndicator()

if let presented = appDelegate.window?.rootViewController?.presentedViewController {
    presented.present(alert, animated: true, completion: nil)
} else {
    appDelegate.window?.rootViewController?.present(alert, animated: true, completion: nil)
}

//Swift 2.0 by Nikhil
// Set light teal color for alert tint color
alert.view.tintColor = UIColor.LTColor()
return alert

1 个答案:

答案 0 :(得分:0)

您正在使用属性字符串设置警报标题,这就是您的字体保持不变的原因。 您可以使用NSAttributedStringKey.font在dictTitleColor中更改它。