iPhone SDK 3.2和UIAppFonts [英] iPhone SDK 3.2 and UIAppFonts

查看:142
本文介绍了iPhone SDK 3.2和UIAppFonts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将自定义字体添加到UIAppFonts并且加载得很好:(显示在 [UIFont familyNames] )。当我在 viewDidLoad {[myLabel setFont:[UIFont fontWithName:@CustomFontsize:65.0]]中手动设置字体时; } 一切正常,字体呈现。

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 { [myLabel setFont: [UIFont fontWithName:@"CustomFont" size: 65.0]]; } everything works and the font is rendered.

然而在IB中做同样的事情却没有(使用其他一些默认字体)。必须为每个标签创建IBOutlets并在viewDidLoad中手动修复字体非常痛苦。

However doing the same thing in IB doesn't (some other default font is used instead). Having to create IBOutlets for each label and fixing up the fonts manually in viewDidLoad is pretty painful.

其他任何人都无法获得自定义字体支持以使用3.2 SDK和IB ?

Anyone else had problems getting the custom font support to work with 3.2 SDK and IB?

推荐答案

有类似问题的问题。并以这种方式修复...

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;
}

希望它能运作。

这篇关于iPhone SDK 3.2和UIAppFonts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆