In my app, while presenting the UIAlertController
it's truncating the message to one line. How to make it display to show full text with word wrap.
Here is my code
let alert = UIAlertController(title: title, message:"Long text" ,
preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
I found the issue.I was overriding the UILabel class in my code. when i have removed the code now it's working fine.
I was also facing the same problem from the last few days but finally found the solution. I removed "padding with UIEdgeInsets" code, it's working fine.
Removed below code
extension UILabel {
public var padding: UIEdgeInsets? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.padding) as? UIEdgeInsets
}
set {
if let newValue = newValue {
objc_setAssociatedObject(self, &AssociatedKeys.padding, newValue as UIEdgeInsets, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
}
UIAlertviewController. Hope it will help!!!
Since Swift 4 you can use multi-line strings: https://www.hackingwithswift.com/example-code/language/how-to-create-multi-line-string-literals
Example:
let longString = """
When you write a string that spans multiple
lines make sure you start its content on a
line all of its own, and end it with three
quotes also on a line of their own.
Multi-line strings also let you write "quote marks"
freely inside your strings, which is great!
"""
So, your code would be:
let longTextMessage = """
When you write a string that spans multiple
lines make sure you start its content on a
line all of its own, and end it with three
quotes also on a line of their own.
Multi-line strings also let you write "quote marks"
freely inside your strings, which is great!
"""
let alert = UIAlertController(title: title, message:longTextMessage, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
LE: I used your code with a long text message like:
let alert = UIAlertController(title: title, message:"Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text ",
preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
Nothing gets truncated.. there's something else that is messing with your alertController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With