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.