iPhone SDK 3.2 and UIAppFonts

前端 未结 3 742
栀梦
栀梦 2020-12-15 12:06

I\'ve added my custom font to UIAppFonts and it\'s loaded just fine: (shows up in [UIFont familyNames] ). When I manually set the font in viewDidLoad { [m

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 12:53

    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.

提交回复
热议问题