Friday 15 June 2012

ios - Use a custom font only in test target? -



ios - Use a custom font only in test target? -

i'd utilize custom font in ios in test target. in test target.

use case: generate screenshots our app xctest target. add together text custom font.

so need custom font in test target, not in main app.

any ideas how solve issue?

to load font test target run within test bundle:

nsbundle *bundle = [nsbundle bundleforclass:[self class]]; nsstring *path = [bundle pathforresource:fontfilename oftype:@"ttf"]; nsdata *indata = [nsdata datawithcontentsoffile:path]; cferrorref error; cgdataproviderref provider = cgdataprovidercreatewithcfdata((__bridge cfdataref)indata); cgfontref font = cgfontcreatewithdataprovider(provider); if (!ctfontmanagerregistergraphicsfont(font, &error)) { cfstringref errordescription = cferrorcopydescription(error); nslog(@"error loading font: %@", errordescription); cfrelease(errordescription); } cfrelease(font);

ios xcode uifont

No comments:

Post a Comment