iPhone SDK 3.2 and UIAppFonts

倾然丶 夕夏残阳落幕 提交于 2019-11-28 23:56:02

Opened a bug report with Apple and turns out it really is a bug. The workaround I ended up using is this:

// LabelQuake.h
@interface LabelQuake : UILabel
@end

// LabelQuake.m
@implementation LabelQuake

    - (id)initWithCoder:(NSCoder *)decoder {
        if (self = [super initWithCoder: decoder]) {
            [self setFont: [UIFont fontWithName: @"Quake" size: self.font.pointSize]];
        }

        return self;
    }
@end

Wrote a bit longer post at our blog.

had simillar kind of problem.and fixed it in this way...

add my custom font to my Resource group. then load all the fonts by the code given bellow:

- (NSUInteger) loadFonts{
NSUInteger newFontCount = 0;
NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
if (frameworkPath) {
    void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
    if (graphicsServices) {
        BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
        if (GSFontAddFromFile)
            for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:nil])
                newFontCount += GSFontAddFromFile([fontFile UTF8String]);
    }
}

return newFontCount;}


 - (id)initWithCoder:(NSCoder *)decoder {
    //load the fonts
    [self loadFonts];

    if (self = [super initWithCoder: decoder]) {
        [self setFont: [UIFont fontWithName: @"Quake" size: self.font.pointSize]];
    }

    return self;
}

Hope it will work.

If you don't want to have to subclass, this solution worked quick and dirty for me. Of course it assumes that all labels have the same font, and in my case that was the case.

for (UIView *v in view.subviews) {

    if ([v isKindOfClass:[UILabel class]]) {
      UILabel *label = (UILabel*)v;

      [label setFont:[UIFont fontWithName:@"Quake" size:label.font.pointSize]];
    }
}

I put this in a helper class and just called it, passing in my current view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!