为什么我不能在界面构建器中更改字体?

时间:2011-07-12 12:06:33

标签: iphone fonts interface-builder

我将字体更改为界面构建器中的其他已安装字体,它始终保持helvetica。 我是否需要获得开发人员许可才能更改字体或其他内容?

4 个答案:

答案 0 :(得分:7)

在这里,您只能使用fontFamily中提供的那些字体。使用以下代码通过iOS设备查找支持的字体。

NSLog(@"iOS Fonts: %@",[UIFont familyNames]);


iOS Fonts: (
    Thonburi,
    "Snell Roundhand",
    "Academy Engraved LET",
    "Marker Felt",
    "Geeza Pro",
    "Arial Rounded MT Bold",
    "Trebuchet MS",
    Arial,
    "Gurmukhi MN",
    "Malayalam Sangam MN",
    "Bradley Hand",
    "Kannada Sangam MN",
    "Bodoni 72 Oldstyle",
    Cochin,
    "Sinhala Sangam MN",
    "Hiragino Kaku Gothic ProN",
    Papyrus,
    Verdana,
    "Zapf Dingbats",
    Courier,
    "Hoefler Text",
    Helvetica,
    "Hiragino Mincho ProN",
    "Bodoni Ornaments",
    "Apple Color Emoji",
    Optima,
    "Gujarati Sangam MN",
    "Devanagari Sangam MN",
    "Times New Roman",
    Kailasa,
    "Telugu Sangam MN",
    "Heiti SC",
    Futura,
    "Bodoni 72",
    Baskerville,
    "Chalkboard SE",
    "Heiti TC",
    Copperplate,
    "Party LET",
    "American Typewriter",
    AppleGothic,
    "Bangla Sangam MN",
    Noteworthy,
    Zapfino,
    "Tamil Sangam MN",
    "DB LCD Temp",
    "Arial Hebrew",
    "Heiti K",
    Georgia,
    "Heiti J",
    "Helvetica Neue",
    "Gill Sans",
    Chalkduster,
    Palatino,
    "Courier New",
    "Oriya Sangam MN",
    Didot,
    "Bodoni 72 Smallcaps"
)

对于其他字体,您需要在应用程序中添加自定义字体。您可以找到Custom Font in iOS here.

的代码

答案 1 :(得分:2)

这对我有用。将_someView替换为包含要为其设置字体的按钮和标签的父视图。在这个例子中,我将所有UILabel和UIButtons都甩到了特定的字体。使用 - [UIView子视图]允许我避免每个项目的出口。另外,请注意我保留每个项目的字体大小:

- (void) viewDidLoad
{
    NSArray    *allSubviews;

    allSubviews = [_someView subviews];
    for (UIView *subview in allSubviews)
    {
        if (([subview isKindOfClass: [UILabel class]]) || ([subview isKindOfClass: [UIButton class]]))
        {
            UIFont     *font;
            CGFloat    pointSize;

            font = [(UILabel *) subview font];
            pointSize = font.pointSize;
            [(UILabel *) subview setFont: [UIFont fontWithName: @"Bodoni 72 Oldstyle" size: pointSize]];
        }
    }
}

答案 2 :(得分:2)

您可以通过创建UILabel(或UIButton)的子类并在其initWithCoder方法中设置字体来更轻松地实现这一点,该方法在解压缩nib时调用。这意味着您可以在Interface Builder中选择此子类而不是UILabel,并且您可以轻松地在那里更改字体大小,而不是在代码中进行更改。

以下是我使用Sabon字体的示例:

在.h:

@interface UILabelSabon : UILabel {

}

@end

而.m只是:

- (id)initWithCoder:(NSCoder *)decoder {

    if ((self = [super initWithCoder: decoder])) {

        [self setFont: [UIFont fontWithName: @"Sabon" size: self.font.pointSize]];
    }
    return self;
}

答案 3 :(得分:1)

您只需要下载字体的ttf文件,然后将此文件拖放到xcode资源文件夹。 选择info.plist文件 - 右键单击​​并选择打开作为源代码,然后添加以下行: -

<key>UIAppFonts</key>
<array>
    <string>yourfontfilename.ttf </string>
</array>

并以

的形式访问您的新字体
 [UIFont fontWithName:@"yrfontname" size:45]  //remember this fontname of yr font is not file name it is the name of font that can be read by opening this font on font book on mac