Swift_ui_btn of the iOS development series

Source: Internet
Author: User

Import UIKit

Class Viewcontroller:uiviewcontroller {

Declare a BTN

var examplebtn:uibutton!

Override Func Viewdidload () {

Super.viewdidload ()

Declaring a method

MAKEBTN ()

Additional setup after loading the view, typically from a nib.

}

Method

Private Func makebtn () {

Initialization

SELF.EXAMPLEBTN = Uibutton.init ()

Set frame

Self.exampleBtn.frame = CGRectMake (100, 100, 60, 60)

Set Background color

Self.exampleBtn.backgroundColor = Uicolor.lightgraycolor ()

Set BTN Font Size

Self.exampleBtn.titleLabel?. Font = uifont.systemfontofsize (12)

Set the text of a btn

Self.exampleBtn.setTitle ("Clickbnt", ForState:UIControlState.Normal)

Tagged tag

Self.exampleBtn.tag = 520

Add a Click event

Self.exampleBtn.addTarget (Self, Action: "Clickbtndown:", ForControlEvents:UIControlEvents.TouchUpInside)

Set up a picture of btn

Self.exampleBtn.setImage (UIImage (imageliteral: "103"), ForState:UIControlState.Normal)

Self.view. Addsubview (SELF.EXAMPLEBTN)

}

BTN Click events

Func Clickbtndown (Btn:uibutton) {

Print ("\ (Btn.tag)")

}

Override Func didreceivememorywarning () {

Super.didreceivememorywarning ()

Dispose of any resources the can be recreated.

}

}

Swift_ui_btn of the iOS development series

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.