Swift如何更改UIAlertController的标题颜色 [英] Swift How to change UIAlertController's Title Color

查看:770
本文介绍了Swift如何更改UIAlertController的标题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Swift更改UIAlertController的标题字体?



我不是在说消息颜色,我不是在说这些按钮的颜色。 / p>

我在谈论标题。

解决方案

  let attributString = NSAttributedString(string:Title,属性:[
NSFontAttributeName:UIFont.systemFontOfSize(15),//你的字体这里
NSForegroundColorAttributeName:UIColor.redColor()
])
let alert = UIAlertController(title:,message:,preferredStyle:.Alert)

alert.setValue(attributString,forKey:attributTitle)
let cancelAction = UIAlertAction(title:Cancel,
style:.Default){(action:UIAlertAction!) - >


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

将正确的代码行添加到我的答案中,因为它比下面的答案更简洁。


How do I change the UIAlertController's Title font using Swift?

I'm not talking about the message color, I'm not talking about the buttons color.

I'm talking about the Title.

解决方案

let attributedString = NSAttributedString(string: "Title", attributes: [
    NSFontAttributeName : UIFont.systemFontOfSize(15), //your font here
    NSForegroundColorAttributeName : UIColor.redColor()
])
let alert = UIAlertController(title: "", message: "",  preferredStyle: .Alert)

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

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

Added the correct line of code to my answer as it's much more concise than the answer below.

这篇关于Swift如何更改UIAlertController的标题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆