我想用Swift更改消息框标题和消息的字体大小。
我不想要字体颜色或字体系列。我只是想改变字体大小和行高。
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)
答案 0 :(得分:-1)
您需要更改密钥
请检查以下代码:
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)