Uibutton defines and sets rounded corners

Source: Internet
Author: User
// 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 */

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.