UIButton *testbutton =[UIButton Buttonwithtype:uibuttontypesystem]; [Testbutton setframe:cgrectmake (Self.view.frame.size.width/2, self.view.frame.size.height/2, -, -)]; [Testbutton settitle:@"Get screen size"Forstate:uicontrolstatenormal]; [Testbutton.layer Setmaskstobounds:yes];//setting the corner radius of a button is not obscured[Testbutton.layer Setcornerradius:Ten]; [Testbutton.layer setborderwidth:2];//set the width of the boundary//set the border color of a buttoncgcolorspaceref colorspaceref=Cgcolorspacecreatedevicergb (); Cgcolorref Color= Cgcolorcreate (Colorspaceref, (cgfloat[]) {1,0,0,1}); [Testbutton.layer Setbordercolor:color]; [Testbutton addtarget:self Action: @selector (Touch) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:testbutton];
Effect:
IOS UIButton modifying rounded corners and borders