通过alertVc.setValue(attributeText, forKey: "attributedMessage")
可修改UIAlertController的显示样式。
func alertMessage(message:String,aligmentLeft:Bool = false,block:(@escaping (_ action:UIAlertAction)->Void)) {
let alertVc = UIAlertController(title: "有新的版本", message: message, preferredStyle: UIAlertController.Style.alert)
if aligmentLeft && message.trim().count != 0{
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
let messageText = NSMutableAttributedString(
string: message,
attributes: [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 14),
NSAttributedString.Key.foregroundColor : UIColor.black
]
)
alertVc.setValue(messageText, forKey: "attributedMessage")
}
let action1 = UIAlertAction(title: "更新", style: UIAlertAction.Style.default) { (action:UIAlertAction) in
block(action)
}
let action2 = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) { (action:UIAlertAction) in
block(action)
}
alertVc.addAction(action1)
controller.present(alertVc, animated: true, completion: nil)
}