I'm trying to change the title fontSize
in an UIAlertController
, but I can't manage how to set my NSMutableAttributedString
to the title
-property.
So for I've been creating the NSMutableAttributedString
with the following code:
let title = NSMutableAttributedString(string: user.fullName)
let range = NSRange(location: 0, length: title.length)
title.addAttribute(NSAttributedStringKey.font, value: UIFont.TextStyle.largeTitle, range: range)
Now the tricky part for me is how to figure out how to set the new title to the UIAlertController
, because it's expecting a String?
value.
I looked around and found out that I should probably create a UILabel
within the completion block when presenting the UIAlertController
. But how do I override the title
-property in the UIAlertController
with my own custom UILabel
?
present(myUIAlertController, animated: true) {
// Creating the UILabel depending on string length
// Set the NSMutableAttributedString value to the custom UILabel and override title property.
}
Or maybe there's even an easier way to solve this?
You can make title and message of
UIAlertController
attributed by using this code. You can customize as per your need. You can see the result in the image. I am not sure you can put it on Appstore.There is no way except using of private API.
I can suggest you to make your AlertViewController with properties that you want to customize.