Is there a way to change the alignment of the message displayed inside a UIAlertController on iOS 8?
I believe accessing the subviews and changing it for the UILabel is not possible anymore.
Is there a way to change the alignment of the message displayed inside a UIAlertController on iOS 8?
I believe accessing the subviews and changing it for the UILabel is not possible anymore.
This property exposes the text fields, so could probably be used to configure them:
Note: even though it says the property is
readonly
, it returns an array of text field object references which can be used to modify the controls.I have successfully used the following, for both aligning and styling the text of UIAlertControllers:
You can do a similar thing with the title, if you use
"attributedTitle"
, instead of"attributedMessage"
Swift 3 update
The above still works in Swift 3, but the code has to be slightly altered to this:
Swift 4 update
Navigate to subview tree until you get to the UILabels for the title and the message
However, you may want to make an category for it
Then you can align the text like this
The following method will set the text alignment, while preserving the default font size.
Swift 4.2 + multiline string linebreak indentation
Use the below code