【问题标题】:How to change font size in iOS Alert Message Box Title and Message with Swift如何使用 Swift 更改 iOS 警报消息框标题和消息中的字体大小
【发布时间】:2016-10-19 23:18:05
【问题描述】:

我想用 Swift 更改消息框 titlemessage字体大小
我不想要字体颜色或字体系列。我只想改变字体大小和行高。

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)

【问题讨论】:

标签: swift uialertview font-size uialertcontroller


【解决方案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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    相关资源
    最近更新 更多