// Login button //. define uibutton * _ loginbtn in H; @ property (strong, nonatomic) uibutton * loginbtn ;//. m to implement the setting button @ synthesize loginbtn = _ loginbtn; // use the backup variable name // set the button shape self. loginbtn = [uibutton buttonwithtype: uibuttontyperoundedrect];/* buttonwithtype: defines the shape of a button. Six Types of buttons are defined: The following figure shows the uibuttontypecustom = 0, no type, the four corners are arc-type uibuttontypedetaildisclosure, uibuttontypeinfolight, uibuttontypeinfodark, uibuttontypecontactadd ,*/
There are six types of buttons:
Uibuttontypecustom = 0, no type
Uibuttontyperoundedrect. The four corners are arc-shaped.
Uibuttontypedetaildisclosure
Uibuttontypeinfolight
Uibuttontypeinfodark
Uibuttontypecontactadd
// Define the coordinates (positions) of the button on the frame, and the width/height of the button self. loginbtn. frame = cgrectmake (40,200, 80, 30); [self. loginbtn settitle: @ "login" forstate: uicontrolstatenormal];/* common attributes: settitle: Set the name of the button setimage: [uiimage imagenamed: @ "image name"] add image settitlecolor: [uicolor redcolor] Set Font color forstate setting button click the front and back status: The following figure shows the uicontrolstatehighlighted uicontrolstateselected uicontrolstatedisabled uicontrolstatenormal */
Forstate setting button
Click before and after
Uicontrolstatehighlighted
Uicontrolstateselected
Uicontrolstatedisabled
Uicontrolstatenormal
// Add an action for the button // action: the method to be executed if you click [self. loginbtn addtarget: Self action: @ selector (LOGIN :) forcontrolevents: uicontroleventtouchupinside]; // Add the button control to the view to display [self. view addsubview: Self. loginbtn]; [CPP] view plaincopy // Method for executing an action-(ibaction) login :( ID) sender;
Uibuttontyperoundedrect is set to this attribute, which can meet our button rounded corner in normal circumstances. When we add a background image and background color on the button, we will find that this attribute is not applicable, because the current button is no longer a rounded corner, it displays the image shape. It can be displayed only when the background color is set to uibuttontypecustom. Therefore, we need to use other properties of the uibutton control to meet our needs [CPP] view plaincopy uibutton * BTN; [BTN. layer setmaskstobounds: Yes]; [BTN. layer setcornerradius: 10.0]; // set the radius of the four rounded corners of the rectangle/* [BTN. layer setborderwidth: 1.0]; // Border Width */