【Swift】UIAlertController使用
func clickButton1(){
创建uialertcontroller
var alertCtl : UIAlertController = UIAlertController(title: "Alert", message: "You clicked button1", preferredStyle: UIAlertControllerStyle.Alert)
添加action到uialertcontroller,action是UIalertcontroller上的按钮操作,建议至少添加一个,如果不添加,alertcontroller就没有相应的按钮退出
var alertAction : UIAlertAction = UIAlertAction(title: "Action", style: UIAlertActionStyle.Default, handler: { (param : UIAlertAction!) -> Void in
println("I am alert action")
var position = self.view.center.x
})
alertCtl.addAction(alertAction)
显示alert controller
self.presentViewController(alertCtl, animated: true, completion: nil)
/*var alertView : UIAlertView = UIAlertView(frame: CGRect(origin: CGPoint(x: 50, y: 200), size: CGSize(width: 100, height: 40)))
alertView.title = "Button1"
alertView.message = "You clicked button1!"
alertView.addButtonWithTitle("Confirm")
alertView.delegate = self
alertView.show()*/
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。