Swift 3 - 警报风格

时间:2017-07-11 09:14:55

标签: ios swift3 alert

我的项目中有一个alertalert与其他每个警报一样简单。我想改变font style and color。怎么可能?

提前致谢!

2 个答案:

答案 0 :(得分:0)

let attributedString = NSAttributedString(string: "YourTitle", attributes: [
    NSFontAttributeName : UIFont.systemFontOfSize(18), //your font here
    NSForegroundColorAttributeName : UIColor.black()
])
let alert = UIAlertController(title: "TextTitle", message: "YourMessage",  preferredStyle: .Alert)

alert.setValue(attributedString, forKey: "attributedTitle")
let cancelAction = UIAlertAction(title: "Cancel",
style: .Default) { (action: UIAlertAction!) -> Void in
}

presentViewController(alert,
animated: true,
completion: nil)

答案 1 :(得分:0)

你可以使用SweetAlert

SweetAlert().showAlert("Here's a message!", subTitle: "It's pretty, isn't it?", style: AlertStyle.None)

完整文档&实施链接:https://github.com/codestergit/SweetAlert-iOS