1:系統(tǒng)提供的提示框如下所示:

系統(tǒng).png
2: 自定制提示框如下:

自定制.png
3: 所用到的方法
(1)可同時(shí)改變字體大小及顏色(第一個(gè)參數(shù)為字典,第二個(gè)為結(jié)構(gòu)體)
alertTitleStr.addAttributes(<#T##attrs: [String : AnyObject]##[String : AnyObject]#>, range: <#T##NSRange#>)
(2)各自設(shè)置字體大小、顏色 (參數(shù)使用見(jiàn)代碼如下)
alertTitleStr.addAttribute(<#T##name: String##String#>, value: <#T##AnyObject#>, range: <#T##NSRange#>)
具體代碼如下:
func createMyAlert(){
let alert = UIAlertController.init(title: "點(diǎn)錯(cuò)了", message: "只能相鄰的圖交換", preferredStyle: .Alert)
let action = UIAlertAction.init(title: "繼續(xù)", style: .Default, handler: nil)
//1.修改title的字體大小及顏色
let alertTitleStr = NSMutableAttributedString.init(string: "點(diǎn)錯(cuò)了")
alertTitleStr.addAttributes([NSFontAttributeName : UIFont.boldSystemFontOfSize(25), NSForegroundColorAttributeName: UIColor.redColor()], range: NSRange.init(location: 0, length: 3))
alert.setValue(alertTitleStr, forKey: "attributedTitle")
//2.修改message的字體大小及顏色
let alertMessageStr = NSMutableAttributedString.init(string: "只能相鄰的圖交換")
alertMessageStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSRange(location: 0, length: 8))
alertMessageStr.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(20), range: NSRange(location: 0, length: 8))
alert.setValue(alertMessageStr, forKey: "attributedMessage")
//3.修改action的顏色 (不能修改action字體大小)
//("_titleTextColor", "titleTextColor"都可以)
//(建議使用“_titleTextColor”, 因?yàn)楫?dāng)我們查看 UIAlertAction的屬性列表中并沒(méi)有它"titleTextColor",“_titleTextColor”是的它的成員變量列表中的一員。)
action.setValue(UIColor.greenColor(), forKey: "_titleTextColor")
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}