2

Possible Duplicate:
iPhone - Convert CTFont to UIFont?

Do you know how I might be able to add Custom fonts to iOS dynamically without adding it to the project before compile time?

I'm looking at a scenario where the fonts are downloaded during run-time of the app, and then loaded dynamically for usage.

If this is possible, I'd like to use it as a UIFont after loading it.

I've searched through a few possibilities to do this, and found that I can load a font using CoreText:

- (CTFontRef)newCustomFontWithFileName:(NSString *)fontFileName
                                ofType:(NSString *)type
                               andSize:(float)pointSize
{
    NSString *fontPath = [[NSBundle mainBundle] pathForResource:fontFileName ofType:type];
    NSData *data = [[NSData alloc] initWithContentsOfFile:fontPath];
    CGDataProviderRef fontProvider = CGDataProviderCreateWithCFData((CFDataRef)data);
    [data release];

    CGFontRef cgFont = CGFontCreateWithDataProvider(fontProvider);
    CGDataProviderRelease(fontProvider);

    CTFontRef font = CTFontCreateWithGraphicsFont(cgFont, pointSize, NULL, NULL);
    CGFontRelease(cgFont);
    return font;
}

However, after doing this, is it possible to convert CTFontRef to a UIFont for usage throughout the app?

Do let me know what you guys know/think ! :)

Community
  • 1
  • 1
Adrian
  • 631
  • 1
  • 6
  • 11
  • 1
    This is **not** a duplicate of that question. The accepted answer to that question relies on the font being a standard font or being part of the app bundle. This question is about fonts downloaded at runtime, and the answer to that other question **will not work** for such fonts. – rob mayoff Aug 15 '12 at 01:42

1 Answers1

0

As of iOS 5.1, there is no public API that creates a UIFont from a CGFont or a CTFont. You are out of luck. :(

Open a feature request at http://bugreport.apple.com if you want them to add an API for this.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848