iphone - iOS: Programmatically add custom font during runtime -


i allow application users use own fonts in app, copying them inside documents directory (through itunes). however, can't find way use custom fonts in way, since right way depends on using uiappfonts key in app's info.plist.

is there way override during runtime?

thanks.

i know old question, trying same today , found way using coretext , cgfont.

first sure add coretext framework ,

#import <coretext/coretext.h> 

then should (in example using font downloaded , saved fonts directory inside documents directory):

nsarray * paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring * documentsdirectory = [paths objectatindex:0];     nsstring * fontpath = [documentsdirectory stringbyappendingpathcomponent:@"fonts/chalkduster.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);      uifont * finalfont = [uifont fontwithname:newfontname size:20.0f]; 

hope helps stumbling across question!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -