Go to the context of the canvas cgcontextref contextual = Uigraphicsgetcurrentcontext (); Canvas size Cgcontextaddrect (context, rect); Canvas color [Self.buttoncolor set]; Fill Cgcontextfillpath (context);
Uibezierpath *rounderectanglepath = [Uibezierpath bezierpathwithroundedrect:cgrectinset (Rect, 1, 1) CornerRadius: RECT.SIZE.HEIGHT/2];
Fill Color
[Self.buttoncolor Setfill];
Connection
[Rounderectanglepath fill];
Line Color
[[Uicolor Whitecolor] setstroke];
Line width
Rounderectanglepath.linewidth = 1;
[Rounderectanglepath stroke];
//
Nsmutableparagraphstyle *paragraphstyle = [[Nsparagraphstyle Defaultparagraphstyle] mutableCopy];
Paragraphstyle.alignment = Nstextalignmentcenter;
Nsdictionary *att = @{nsparagraphstyleattributename:paragraphstyle,nsforegroundcolorattributename:[uicolor Whitecolor],nsfontattributename:[uifont Systemfontofsize:14]};
Cgsize size = [Self.buttontitle Sizewithattributes:att];
CGRect r = CGRectMake (RECT.SIZE.WIDTH/2-SIZE.WIDTH/2, RECT.SIZE.HEIGHT/2-SIZE.HEIGHT/2, Size.width, size.height);
Can be an image, so that you can draw images
[Self.buttontitle drawinrect:r Withattributes:att];
Click Effect
-(void) touchesended: (Nsset *) touches withevent: (uievent *)event { *touch = [ Touches Anyobject]; = Touch.tapcount; Switch (tapcount) { case1: self.buttonclickblock (); Break ; default : Break ; }}
Final effect
. h file
Coregraphics a custom button