所有警报对话框消息和textField都已更改为单行.请检查图像

jaz*_*bpn 7 uitextfield ios swift3 xcode8.2 uialertviewcontroller

以前所有的对话框和textField都运行良好.但不是我不知道这些TextFields如何突然变为单行三联.(就像这里的一些消息......)

    let alert = UIAlertController(title: "Cancel Booking !!", message: "Are you sure you want to cancel your booking?", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "No", style: .default, handler: nil))
    alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: self.cancelMessageDialog))
    self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

演示1 演示3

Bat*_* C. 5

我也遇到了同样的问题,三天三夜后解决了。由于 UIAlertViewController 使用 UILabel 来显示消息,因此我在整个项目中坚定地搜索修改 UILabel 的内容。我意识到搜索结果不包含某些 pod 中的任何内容,这些 pod 的函数名称等中肯定有“标签”关键字。我决定从存储库中下载所有 pod 的源代码,并使用另一个简单的文本编辑器在其中递归搜索,瞧!有些人决定覆盖默认的 UILabel 类,而不是在他们的 pod 中对其进行子类化。罪魁祸首是

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

当我开始搜索 UILabel 扩展时,通过使用 XCode 中的搜索功能,这些并没有显示在搜索结果中。因此,我建议您打开项目中任何第三方框架的源代码并分别在其中进行搜索。UILabel 类肯定有问题。


jaz*_*bpn 0

终于解决了

我通过在 UIViewController 中创建自定义UILable解决了这个问题。这可能不是一个好的做法,所以如果有人找到比这更好的解决方案,请告诉我。

func showTestAlert(message:String , viewController:UIViewController){

    let customUiLableView:UILabel
    let alert:UIAlertController

    if((message.count) < 100){
        alert = UIAlertController(title: "", message: "\n\n\n\n", preferredStyle: .alert)
        customUiLableView = UILabel(frame: CGRect(x: 10, y: 0, width: 250, height: 120))
        customUiLableView.numberOfLines = 4
    }else if((message.count) < 200){
        alert = UIAlertController(title: "", message: "\n\n\n\n\n\n", preferredStyle: .alert)
        customUiLableView = UILabel(frame: CGRect(x: 10, y: 0, width: 250, height: 160))
        customUiLableView.numberOfLines = 6
    }else{
        alert = UIAlertController(title: "", message: "\n\n\n\n\n\n\n\n", preferredStyle: .alert)
        customUiLableView = UILabel(frame: CGRect(x: 10, y: 0, width: 250, height: 200))
        customUiLableView.numberOfLines = 8
    }
    customUiLableView.text = message
    customUiLableView.textAlignment = .center
    customUiLableView.textColor = UIColor.darkGray
    customUiLableView.font = UIFont(name: "Helvetica", size: 16.0)

    let action = UIAlertAction(title: "OK", style: .default, handler: nil)
    alert.view.addSubview(customUiLableView)
    alert.addAction(action)

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

}
Run Code Online (Sandbox Code Playgroud)