Swift - Truncated text in UIAlertController

The alerts in my app are displayed, but they truncate the text. (both title and message)


If i copy the same code and put it on a new project, all text is displayed.

Because of this I think I changed some project configuration, but I dont know how...


Can anyone helpe me?


The code:


func showMessage(title:String,message:String,view:UIViewController) {

    let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
    let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
    alert.addAction(action)

    let color = self.defaultColor()

    alert.setValue(NSAttributedString(string: title, attributes: [NSFontAttributeName : UIFont.boldSystemFont(ofSize: 18),NSForegroundColorAttributeName : color]), forKey: "attributedTitle")

    alert.setValue(NSAttributedString(string: message, attributes: [NSFontAttributeName : UIFont.systemFont(ofSize: 15),NSForegroundColorAttributeName : color]), forKey: "attributedMessage")

    alert.view.tintColor = UIColor.black

    view.present(alert, animated: true, completion: nil)

}

Replies

+1


We are experiencing exactly the same issue, with text getting truncated to one line and are unable to find the cause.

You are using private, undocumented APIs (alert.setValue). If you cannot find an API in the official documentation, you should not be using it since it may break at any time (and possibly cause your app to be rejected by App Review).


Also note the warning in the documentation:


> The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

The same +1. When I upgraded my xcode to 9. This issue starts to happen.

Hi, I'm also experiencing the same issue the text in alert is getting truncated.

Hi! has anyone found a solution to this issue? I'm experiencing the same after updating to Xcode 9, and running the App in iOS 11.

+1

We are facing the same issue. Still unable to find the cause. And other third party alert views are also truncating in this project.

If Someone finds the solution please let me know. Its very urgent.

Same here. Reported last year. No solution yet.

Helllo Friends,

I was facing the same problem from last few days but finally after some R&D it fixed.

Actually I was overiding the properties of UILabel in my code with UILabel extensions.

Moreover, I was also settiing UIlabel padding with UIEdgeInsets property. But after commenting the same lines of code.

It works fine for me!!! Now I am able to see the complete text message in UIAlertviewController.

Hope it will helps !!!

Happy coding...