我知道您可以添加文本字段,但是是否可以向 UIAlertController
添加标签?
alertController.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Hyperlink"
inputTextField = textField
inputTextField?.text="www.google.com"
})
^^文本域
请您参考如下方法:
有适合你的功能:
func showAlertWith(withLabel: String) {
let alert = UIAlertController(title: "Hello!", message: "Hi everybody!\n", preferredStyle: UIAlertController.Style.alert )
let action = UIAlertAction(title: "Ok", style: .default)
alert.addAction(action)
present(alert, animated: true, completion: {
// Add your label
let margin:CGFloat = 8.0
let rect = CGRect(x: margin, y: 72.0, width: alert.view.frame.width - margin * 2.0 , height: 20)
let label = UILabel(frame: rect)
label.text = withLabel
label.textAlignment = .center
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5
alert.view.addSubview(label)
})
}
我没有太在意警报中标签的坐标和选项,但我认为您已经清楚了一般含义。