1

I would like to change the font size of Message box title and message with Swift.
I don't want font color or font family. I just only want to change the font size and line height.

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)
May Phyu
  • 895
  • 3
  • 23
  • 47

1 Answers1

-1

You need to change key for it

Please check below code:

 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)
Anjali jariwala
  • 410
  • 5
  • 15