ImportUIKitclassViewcontroller:uiviewcontroller, uialertviewdelegate {@IBOutlet var label:uilabel?@IBOutlet var Btn:uibutton?@IBAction func Btnclick (anyobject) {Showalert ()} func Showalert () {Let alert=Uialertview () alert.title= "Alert"alert.delegate=Self alert.message= "Hello Apple"Alert.addbuttonwithtitle ("OK") Alert.addbuttonwithtitle ("Cancel") Alert.show ()} override func Viewdidload () {Super. Viewdidload ()//additional setup after loading the view, typically from a nib.} override func didreceivememorywarning () {Super. didreceivememorywarning ()//Dispose of any resources the can be recreated.} func Alertview (Alertview:uialertview!, Clickedbuttonatindex Buttonindex:int) { SwitchButtonindex { Case0: Self.label?. Text = "OK"; Case1: Self.label?. Text = "Cancel"default: println ("Alertview cancel!") } }}
iOS Swift Button, Label, Alertview