Cgcontextshowtextatpoint can be used to draw text in iOS, but this method does not support Chinese characters and is not recommended after iOS7.
We can use NSString's drawatpoint and drawinrect for simpler text rendering.
- (void) DrawRect: (cgrect) rect{//Get Image Context ObjectCgcontextref context =Uigraphicsgetcurrentcontext (); Cgcontextsetrgbstrokecolor (Context, -/255.0, -/255.0, -/255.0,1); Cgcontextsetfillcolorwithcolor (context, [Uicolor Greencolor]. Cgcolor); Cgcontextsetshadowwithcolor (Context, Cgsizemake (1,1),3, [Uicolor Yellowcolor]. Cgcolor); //Draw Text using fill modeCgcontextsettextdrawingmode (Context,kcgtextfill); NSString*str =@"This is a jock"; [Str drawatpoint:cgpointmake ( -, -) withattributes:@{nsfontattributename:[Uifont fontwithn Ame:@"Arial"Size -],nsforegroundcolorattributename:[uicolor Greencolor]}]; //draw Text using stroke modeCgcontextsettextdrawingmode (context, kcgtextstroke); [Str drawatpoint:cgpointmake ( -, -) withattributes:@{nsfontattributename:[ Uifont Fontwithname:@"Arial"Size -],nsforegroundcolorattributename:[uicolor Magentacolor]}]; Cgcontextsettextdrawingmode (context, kcgtextfillstroke); [Str drawinrect:cgrectmake ( -, -, -, -) Withattributes:@{nsfontattributename:[uifont Fontwithname:@"Arial"Size -],nsforegroundcolorattributename:[uicolor Redcolor]}]; }
Run results
iOS image processing (2) Drawing text