All of my UIAlertController messages became single line

别来无恙 提交于 2019-12-23 19:39:19

问题


I am not sure if this is the culprit but the biggest change I did to this project was upgrading to Swift 4 a couple of days ago. I know that my UIAlertController messages were showing multiline when needed but today I realized by chance that all of them became single line and has ellipsis at the end. Since I show these messages from an API, I cannot use "\n". The code is simple enough;

let alert = UIAlertController(title: "Title", message: "Long message that must be shown as multiline", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in
    alert.dismiss(animated: true, completion: nil)
}))
present(alert, animated: true, completion: nil)

I checked some other related questions but none of them worked for me. This one was asked as the same problem recently but did not get an answer, and has a hacky workaround posted as a solution;

All the alert dialog message and textField have been changed to single line. Please checkout the image

Any advice on what to check is really appreciated.


回答1:


Do not know why the downvotes but I have found the issue after 3 days of pulling my hair out. There was a UILabel extension in one of the 3rd party Pods I have been using. Its code was marked as "Locked" so I think that's why it did not show up in the search results before. I had to download the source codes for all of the pods from their repositories and searched inside. It was overriding these functions and properties of the default UILabel, instead of creating its own UILabel subclass;

override open func draw(_ rect: CGRect) {}
override open var intrinsicContentSize: CGSize {}

Since the UIAlertViewController uses UILabel to display the message, I have tried to comment out these lines and my issue went away. If anyone having the same issue, search for UILabel extensions in your code AND in your embedded libraries source codes.



来源:https://stackoverflow.com/questions/48977001/all-of-my-uialertcontroller-messages-became-single-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!