Create custom rounded buttons in iOS

Source: Internet
Author: User

There are many times in iOS that require the use of a rounded button with a specified style, although UIButton provides a way to create a rounded button:

+ (ID) Buttonwithtype: (Uibuttontype) ButtonType; // specify ButtonType as Uibuttontyperoundedrect

However, the created button can only support the default white-bottom blue character style and cannot be changed. For example, changing the backgroundcolor, the background color area still covers the entire rectangular area.

How to do it, through groping, the following methods can meet the requirements:

UIButton *btn = [[UIButton alloc]initwithframe:btnframe];

// set the fillet radius
Btn.layer.masksToBounds = YES;
4;

// You can also set the border width and color
1;
Btn.layer.borderColor = [Uicolor Darkgraycolor]. Cgcolor;

The resulting btn can be defined in the style you want, and the backgroundcolor or backgroundimage are only filled with their rounded corners.

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.