Nt_ios Note-ios The user adds a font after the call

Source: Internet
Author: User

iOS needs to use new fonts, add directly to the line, previously wrote iOS add fonts

But what if the font file is too large, too big, or has no user-preferred fonts?

Let the user manually download fonts or import fonts.

So how do we call these fonts?

All fonts can be found by this method

    Nsarray *familynames =[[nsarray Alloc]initwitharray:[uifont Familynames]];    Nsarray *fontnames;    Nsinteger indfamily, Indfont;    for (Indfamily=0;indfamily<[familynames count];++indfamily)    {        NSLog (@ "Family name:%@", [familynames Objectatindex:indfamily]);        FontNames =[[nsarray Alloc]initwitharray:[uifont fontnamesforfamilyname:[familynames objectAtIndex:indFamily]];                for (indfont=0; indfont<[fontnames count]; ++indfont)                    {            NSLog (@ "Font name:%@", [FontNames Objectatindex: Indfont]);                    }    }
you will find that you cannot find the font you are adding. That's for sure ... The path is wrong.

No, just add it in.

    NSString * Fontpath = [Document_path stringbyappendingpathcomponent:@ "Fonts/tinghei.ttf"];    Nsurl * url = [Nsurl Fileurlwithpath:fontpath];    Cgdataproviderref Fontdataprovider = Cgdataprovidercreatewithurl ((__bridge cfurlref) URL);    Cgfontref NewFont = Cgfontcreatewithdataprovider (fontdataprovider);    NSString * Newfontname = (__bridge NSString *) cgfontcopypostscriptname (newFont);    Cgdataproviderrelease (Fontdataprovider);    Cferrorref error;    Ctfontmanagerregistergraphicsfont (NewFont, &error);    Cgfontrelease (NewFont);

OK, done, you can verify the call method above to see if there is a newly added font.

Now it can be called, the name of the font is "Newfontname".




Nt_ios Note-ios The user adds a font after the call

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.