Import Uikit@uiapplicationmainclassAppdelegate:uiresponder, uiapplicationdelegate {var window:uiwindow?func Application (application:uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject:anyobject]< /c3>?) -Bool {Self.window=UIWindow (Frame:UIScreen.mainScreen (). Bounds)//Override point for customization after application launch.self.window!. BackgroundColor =Uicolor.whitecolor () Self.window!. Rootviewcontroller =Rootviewcontroller () Self.window!. makekeyandvisible ()return true }}
Import UIKitclassRootviewcontroller:uiviewcontroller {Overridefunc viewdidload () {super.viewdidload ()//Initialize buttonLet btn =UIButton (Type:UIButtonType.Custom)//DimensionsBtn.frame = CGRect (x: -Y: -, Width: -, Height: -) //Background ColorBtn.backgroundcolor =Uicolor.redcolor ()//Set TitleBtn.settitle ("Button", ForState:UIControlState.Normal)//set the color of a captionBtn.settitlecolor (Uicolor.greencolor (), ForState:UIControlState.Normal)//Add a Click eventBtn.addtarget (Self, Action:"printsomething:", ForControlEvents:UIControlEvents.TouchUpInside)//Self.view Loading a child view btnSelf.view.addSubview (BTN)}//Click the button to execute the methodfunc printsomething (Button:uibutton) {print (button)}}
Basic usage of SWIFT button