版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21153627/article/details/84070052
func test6() {
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
button.setTitle("点击弹出警告⚠️", for: UIControlState())
button.backgroundColor=UIColor.purple
button.addTarget(self, action: #selector(ViewController.test6OnClick), for: UIControlEvents.touchUpInside);
self.view.addSubview(button)
}
@objc func test6OnClick(_ button:UIButton){
let dialog=UIAlertController(title: "Information", message: "Are you a student?", preferredStyle: UIAlertControllerStyle.alert);
let yes=UIAlertAction(title: "Yes", style: UIAlertActionStyle.default, handler: {(Alerts:UIAlertAction) -> Void in print("Yes,I'm a student")})
let no = UIAlertAction(title: "no", style: UIAlertActionStyle.default, handler: {(Alerts:UIAlertAction) -> Void in print("no,I'm not a student")})
dialog.addAction(yes)
dialog.addAction(no)
self.present(dialog, animated: true, completion: nil);
}