【Swift】UIAlertController使用

來源:互聯網
上載者:User

標籤:

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()*/

    }

【Swift】UIAlertController使用

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.