How to use UITextView in UIAlertController

后端 未结 6 1372
悲哀的现实
悲哀的现实 2020-12-16 18:48

I created a popup alert using alert controller and added two alert actions(ok and cancel) as below.

UIAlertController * alert=   [UIAlertController
                  


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 19:14

    Swift 3

     let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
     let textView = UITextView()
     textView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    
     let controller = UIViewController()
    
     textView.frame = controller.view.frame
     controller.view.addSubview(textView)
    
     alert.setValue(controller, forKey: "contentViewController")
    
     let height: NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: view.frame.height * 0.8)
     alert.view.addConstraint(height)
    
     present(alert, animated: true, completion: nil)
    

提交回复
热议问题