小编典典

UIAlertController内的多行可编辑文本UITextview?

swift

我怎样才能让一个多可编辑的文本UITextview里面UIAlertControllerUITextfield支持单行,我们需要在弹出窗口中创建一个多行文本编辑框。


阅读 599

收藏
2020-07-07

共1个答案

小编典典

这是很好的环境…

func popUpController()
{

    let alertController = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertController.Style.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 customView = UITextView(frame: rect)

    customView.backgroundColor = UIColor.clear
    customView.font = UIFont(name: "Helvetica", size: 15)



    //  customView.backgroundColor = UIColor.greenColor()
    alertController.view.addSubview(customView)

    let somethingAction = UIAlertAction(title: "Something", style: UIAlertAction.Style.default, handler: {(alert: UIAlertAction!) in print("something")

        print(customView.text)

    })

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: {(alert: UIAlertAction!) in print("cancel")})

    alertController.addAction(somethingAction)
    alertController.addAction(cancelAction)

    self.present(alertController, animated: true, completion:{})


}
2020-07-07