Use of Swift-alarm box (Uialertview)

Source: Internet
Author: User

1, the following code creates and pops up an alarm box with a "Cancel" "OK" button of two

(note: Since IOS8, we recommend using Uialertcontroller)
123456789101112131415161718192021222324 class ViewController: UIViewController{    override func viewDidLoad() {        super.viewDidLoad()        var alertView = UIAlertView()        alertView.title = "系统提示"        alertView.message = "您确定要离开hangge.com吗?"        alertView.addButtonWithTitle("取消")        alertView.addButtonWithTitle("确定")        alertView.cancelButtonIndex=0        alertView.delegate=self;        alertView.show()    }    func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: Int){        if(buttonIndex==alertView.cancelButtonIndex){            println("点击了取消")        }        else        {            println("点击了确认")        }    }}


2, the Alarm box has the following 4 kinds of styles
Default: Defaults style
Plaintextinput: Alarm box with input box
Securetextinput: Alarm box with Password box
Loginandpasswordinput: Alarm box with input box and password box


Here is an example of an alarm box using an input box and a password box:

1234567891011121314151617181920212223242526272829303132333435 import UIKitclass ViewController: UIViewController {    var alertView = UIAlertView()        override func viewDidLoad() {        super.viewDidLoad()                alertView.title = "系统登录"        alertView.message = "请输入用户名和密码!"        alertView.addButtonWithTitle("取消")        alertView.addButtonWithTitle("确定")        alertView.cancelButtonIndex=0        alertView.delegate=self;        alertView.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput        alertView.show()    }        func alertView(alertView:UIAlertView, clickedButtonAtIndex buttonIndex: Int){        if(buttonIndex==alertView.cancelButtonIndex){            println("点击了取消")        }        else        {            let name = alertView.textFieldAtIndex(0)            let password = alertView.textFieldAtIndex(1)            println("用户名是:\(name!.text) 密码是:\(password!.text)")        }    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}

Use of Swift-alarm box (Uialertview)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.