iOS value string Dynamic writing

Source: Internet
Author: User

/** String Animation written @param string to be written @param view parent view @param ui_font font size @param color font*/- (void) Createanimationlayerwithstring: (nsstring*)stringAndview: (UIView *) View Andfont: (uifont*) Ui_font Andstrokecolor: (uicolor*) color{ctfontref font=ctfontcreatewithname (cfstringref) ui_font.fontname, Ui_font.pointsize,    NULL); Cgmutablepathref Letters=cgpathcreatemutable (); //This sets the font and size of the drawing lineNsdictionary *attrs =[nsdictionary Dictionarywithobjectsandkeys: (__bridgeID) font, kctfontattributename, nil]; Nsattributedstring*attrstring = [[Nsattributedstring alloc] initwithstring:stringAttributes:attrs]; Ctlineref Line=ctlinecreatewithattributedstring ((cfattributedstringref) attrstring); Cfarrayref Runarray=Ctlinegetglyphruns (line);  for(Cfindex Runindex =0; Runindex < Cfarraygetcount (Runarray); runindex++) {Ctrunref run=(ctrunref) cfarraygetvalueatindex (Runarray, Runindex); Ctfontref Runfont=Cfdictionarygetvalue (Ctrungetattributes (run), kctfontattributename);  for(Cfindex Runglyphindex =0; Runglyphindex < Ctrungetglyphcount (run); runglyphindex++) {Cfrange Thisglyphrange= Cfrangemake (Runglyphindex,1);            Cgglyph Glyph;            Cgpoint position; Ctrungetglyphs (Run, Thisglyphrange,&glyph); Ctrungetpositions (Run, Thisglyphrange,&position); Cgpathref Letter=ctfontcreatepathforglyph (Runfont, Glyph, NULL); Cgaffinetransform T=cgaffinetransformmaketranslation (position.x, POSITION.Y); Cgpathaddpath (Letters,&T, letter);        Cgpathrelease (letter); }} Cashapelayer*pathlayer =[Cashapelayer layer]; Pathlayer.frame= CGRectMake (0,0, View.frame.size.width, view.frame.size.height); Pathlayer.bounds=Cgpathgetboundingbox (Letters); pathlayer.geometryflipped=YES; Pathlayer.path=letters; Pathlayer.strokecolor=[Color Cgcolor]; Pathlayer.fillcolor=Nil; Pathlayer.linewidth=1.0f; Pathlayer.linejoin=Kcalinejoinbevel;        [View.layer Addsublayer:pathlayer]; Cabasicanimation*pathanimation = [Cabasicanimation animationwithkeypath:@"Strokeend"]; Pathanimation.duration=5.0; Pathanimation.fromvalue= [NSNumber numberwithfloat:0.0f]; Pathanimation.tovalue= [NSNumber numberwithfloat:1.0f]; [Pathlayer addanimation:pathanimation Forkey:@"Strokeend"];    Cgpathrelease (Letters);    Cfrelease (font); Cfrelease (line);}

iOS value string Dynamic writing

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.