Reprinted from: HTTP://WWW.JIANSHU.COM/P/451B7FA94E2A
The first kind: I think you see the code, the moment there is the urge to vomit, the most common one way ...
uibutton *button = [[UIButton Alloc]init]; Button.frame = CGRectMake (100 , 100 , 100 , 40 = [Uicolor Redcolor]; Button.layer.cornerRadius = 20.0f ; Button.layer.masksToBounds = YES;
[Button Settitle: @ " test " Forstate:uicontrolstatenormal]; [Self.view Addsubview:button];
So simple ... However, it is by default forced to cut off the four corners ah ... That's the problem, if the demand only requires cutting a corner ... Look at the second method.
The second: or in layer the fuss, the different use of the extension of the method, followed by the UIButton example, the specific effect to see:
#import "Uibutton+corner.h"@implementationUIButton (Corner)- (void) corner{cgrect bounds=Self.bounds; Uibezierpath*maskpath = [Uibezierpath bezierpathwithroundedrect:bounds byroundingcorners:uirectcornerbottomleft cornerRadii: Cgsizemake ( -, -)]; Cashapelayer*masklayer =[Cashapelayer layer]; Masklayer.frame=bounds; Masklayer.path=Maskpath.cgpath; [Self.layer Addsublayer:masklayer]; Self.layer.mask=Masklayer;}@end
typedef ns_options (Nsuinteger, Uirectcorner) { uirectcornertopleft 10, uirectcornertopright 1 1 , Uirectcornerbottomleft 12, 13, uirectcornerallcorners = ~0UL};
IOS: Two ways to implement UIView chamfer