iOS image processing (2) Drawing text

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.