如何使用Swift更改iOS警报消息框标题和消息中的字体大小
我想用Swift更改消息框标题和消息的字体大小。 我不想要字体颜色或字体系列。我只想更改字体大小和行高如何使用Swift更改iOS警报消息框标题和消息中的字体大小,swift,uialertview,font-size,uialertcontroller,Swift,Uialertview,Font Size,Uialertcontroller,我想用Swift更改消息框标题和消息的字体大小。 我不想要字体颜色或字体系列。我只想更改字体大小和行高 let attributedString = NSAttributedString(string: "Title", attributes: [ NSFontAttributeName : UIFont.systemFontOfSize(15) //your font here, NSForegroundColorAttributeName : UIColor.redColor()]) let
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)
您需要为它更改密钥 请检查以下代码:
let alert = UIAlertController(title: "Test Title", message: "Custom Fonts in Alert Controller", preferredStyle: .actionSheet)
let strAction = NSMutableAttributedString(string: "Presenting the great...")
strAction.addAttribute(NSAttributedStringKey.font, value: UIFont.systemFont(ofSize: 30), range: NSMakeRange(24, 11))
alert.setValue(action, forKey: "attributedMessage")// change key name if you want to change title font with attributedTitle
let action = UIAlertAction(title: "Some title", style: .default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)
您使用的是哪个版本的iOS?您可以参考我的发展目标是9.0