iOS UIAlertview with uitextview editable

前端 未结 2 1375
轮回少年
轮回少年 2021-01-27 06:26

I\'m searching for a way of putting an UITextView editable inside an UIAlertView.

I know how to put a simple textfield with :

alert.alertViewStyle = UIAl         


        
2条回答
  •  遇见更好的自我
    2021-01-27 07:09

    Add a custom view into the alert view.

    Change preferredStyle to .alert and .actionsheet as per the requirement.

    func showPopUpWithTextView() {
            let alertController = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: .actionSheet)
    
            let margin:CGFloat = 8.0
            let rect = CGRect(x: margin, y: margin, width: alertController.view.bounds.size.width - margin * 4.0, height: 100.0)
            let textView = UITextView(frame: rect)
            textView.backgroundColor = .clear
    
            alertController.view.addSubview(textView)
    
            let submitAction = UIAlertAction(title: "Something", style: .default, handler: {(alert: UIAlertAction!) in print("Submit")
                print(textView.text)
            })
    
            let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {(alert: UIAlertAction!) in print("cancel")})
    
            alertController.addAction(submitAction)
            alertController.addAction(cancelAction)
    
            self.present(alertController, animated: true, completion:{})
        }
    

提交回复
热议问题