所以现在是2014年,是否已经有一种方法可以在Interface Builder中设置自定义字体?也就是说,不要通过编程来实现,除了在应用程序的plist中提供的“应用程序提供的字体”。
所以现在是2014年,是否已经有一种方法可以在Interface Builder中设置自定义字体?也就是说,不要通过编程来实现,除了在应用程序的plist中提供的“应用程序提供的字体”。
是的,Marrius说得对。在Xcode 6中,您无需使用额外的软件或在代码文件中设置字体。只需将字体文件与其他文件一起添加到项目中,Interface Builder将在自定义字体列表中显示已添加的字体。
最令人惊奇的是,Xcode 6会立即在IB中显示应用的字体。这是苹果公司的伟大补充。
还要确保在项目的info.plist中添加此键“Fonts provided by application”并提供您的字体文件名称以在设备上看到效果。
在Xcode 6中,只需将ttf文件添加到您的项目中,并通过自定义字体在storyboard中使用它。 如果您想要直接在代码中使用它而不是在storyboard中使用它,则必须在projectName-Info.plist中添加键"UIAppFonts"。
示例:
<key>UIAppFonts</key>
<array>
<string>Signika-Bold.ttf</string>
<string>Signika-Regular.ttf</string>
<string>Signika-Light.ttf</string>
<string>Signika-Semibold.ttf</string>
</array>
</dict>
这行代码之前。UIFont* font = [UIFont fontWithName:@"Signika-Regular" size:25];
#import "UILabelEx.h"
#import "Constants.h"
@implementation UILabelEx
//- (void)layoutSubviews
//{
// [super layoutSubviews];
// // Implement font logic depending on screen size
// self.font = [UIFont fontWithName:@"CustomFont" size:self.font.pointSize];
//}
- (void) traitCollectionDidChange: (UITraitCollection *) previousTraitCollection {
[super traitCollectionDidChange: previousTraitCollection];
self.font = [UIFont fontWithName:APP_FONT size:self.font.pointSize];
}
@end