One of the iOS Development series-UIButton Usage Summary

Source: Internet
Author: User

Initialize the button and set the type UIButton *btn = [UIButton buttonwithtype:uibuttontyperoundedrect];//can define the following 6 types of UIButton://typedef enum {//Uibuttontypecustom = 0, custom style//Uibuttontyperoundedrect, Rounded rectangle//Uibuttontypedet            Aildisclosure, Blue small arrow button, mainly to do the detailed description with//Uibuttontypeinfolight, bright exclamation mark//Uibuttontypeinfodark, Dark exclamation point//Uibuttontypecontactadd, Cross plus button//} uibuttontype;//Set button size and position btn.frame = CGRectMake (20, 360, 280, 45);//Set button background color Btn.backgroundcolor = [Uicolor colorwithred:254/255.0f green:254/255.0f blue:254/255.0f alpha:1.0f ];//Set button text [btn settitle:@ "Normal" forstate:uicontrolstatenormal];    [Btn settitle:@ "Pressed" forstate:uicontrolstatehighlighted];//forstate This parameter is the role of defining the button text or picture in which state will appear, the following are several states://      enum {//UIControlStateNormal = 0, General status Show//uicontrolstatehighlighted = 1 << 0, Highlight status Show//uicontrolstatedisabled = 1 << 1, disabled status will only show//Uicontrolstateselected = 1 << 2, check status//Uicontrolstateapplication = 0x00ff0000 when application flag//Uicontrol statereserved = 0xff000000 is reserved for internal frame, can be set button text color regardless of his//};//[btn settitlecolor:[uicolor Redcolor] Forstate:uicontrols tatenormal];//Set button text font [Btn.titlelabel Setfont:[uifont systemfontofsize:17]; [Btn.layer setmaskstobounds:yes];//Set button four fillet radius [btn.layer setcornerradius:4.0];//Set button border Width [Btn.layer setborderwidth : 0.5];//Set button border color cgcolorref colorref = Cgcolorcreate (Cgcolorspacecreatedevicergb (), (cgfloat[]) {168/255.0f, 168/ 255.0f, 168/255.0f, 1.0}); [Btn.layer setbordercolor:colorref];//Remove button Press delay in overlay view tableview.delayscontenttouches = no;//Add Click event [btn addTarget: Self action: @selector (btnaction:) forcontrolevents:uicontroleventtouchupinside];//Displays the button in the view [TableView addsubview: btn];//button click Event-(void) Btnaction: (ID) sender{//Do something}

This article fixed link: http://www.itechzero.com/coding/objective-c/ios-development-series-one-uibutton-usage-summary/, reprint please indicate the source.

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.