ios Interface Builder 中的自定义字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22035985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:35:05  来源:igfitidea点击:

Custom fonts in Interface Builder

iosfontsinterface-builder

提问by Jonny

So we're in 2014, is there any way to set custom fonts within Interface Builder yet? Ie don't do it programmatically, except for "Fonts provided by application" in the app's plist.

所以我们在 2014 年,有没有办法在 Interface Builder 中设置自定义字体?即不要以编程方式执行此操作,除了应用程序 plist 中的“应用程序提供的字体”。

回答by Asif Bilal

Yes, Marrius is right. In Xcode 6, you neither need to use extra software nor to set Font in Code files. Just add your font files in your project along with other files. And Interface builder will display the added fonts in the Custom Font List.

是的,马吕斯是对的。在 Xcode 6 中,您既不需要使用额外的软件,也不需要在代码文件中设置字体。只需将您的字体文件与其他文件一起添加到您的项目中。并且界面生成器将在自定义字体列表中显示添加的字体。

And the most amazing thing is, xcode 6 shows the applied font instantly in IB. This is the great addition by Apple.

最令人惊奇的是,xcode 6 在 IB 中立即显示了应用的字体。这是苹果公司的一大补充。

Also make sure to add this key "Fonts provided by application" in your project's info.plist and provide your font file names to see the effect in devices.

还要确保在您的项目的 info.plist 中添加此键“应用程序提供的字体”并提供您的字体文件名以查看设备中的效果。

回答by Marius Popescu

In Xcode 6, we have custom fonts available in interface builder.

在 Xcode 6 中,我们在界面构建器中提供了自定义字体。

No need for extra software. Thank you Apple!

不需要额外的软件。谢谢苹果!

回答by ankurkumar

In Xcode 6, just add the ttf file in your project and use it in storyboard through custom fonts. If you directly want to use it in your code without using it in storyboard then you have to add key "UIAppFonts" in projectName-Info.plist.

在 Xcode 6 中,只需在您的项目中添加 ttf 文件并通过自定义字体在故事板中使用它。如果您想直接在代码中使用它而不在故事板中使用它,那么您必须在 projectName-Info.plist 中添加键“UIAppFonts”。

Example:

例子:

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

just before the line </dict>in projectName-Info.plist.

</dict>在 projectName-Info.plist 中的行之前。

UIFont* font  = [UIFont fontWithName:@"Signika-Regular" size:25];

回答by Jules

This is my solution, nothing else worked for me

这是我的解决方案,没有其他方法对我有用

#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

回答by rdurand

Looks like someone worked on it. You can have a look at MoarFonts:

看起来有人在研究它。你可以看看MoarFonts

MoarFonts

Use custom fonts for your iOS projects directly in Interface Builder, the WYSIWYG way

by Cédric Luthi “0xced

摩尔字体

直接在 Interface Builder 中为您的 iOS 项目使用自定义字体,WYSIWYG 方式

作者:Cédric Luthi “ 0xced

It costs 10$, but :

它花费10 美元,但是:

Since iOS 3.2, you can use custom fonts in your iOS apps by adding the UIAppFonts Info.plist key. Unfortunately, custom fonts are not available when editing your xib files in Interface Builder. MoarFonts makes your custom fonts available right within Interface Builder.

MoarFonts is compatible with both Xcode 4 and Xcode 5.

从 iOS 3.2 开始,您可以通过添加 UIAppFonts Info.plist 键在您的 iOS 应用程序中使用自定义字体。不幸的是,在 Interface Builder 中编辑您的 xib 文件时,自定义字体不可用。MoarFonts 使您的自定义字体可以直接在 Interface Builder 中使用。

MoarFonts 兼容 Xcode 4 和 Xcode 5。