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