简体   繁体   English

Interface Builder中的自定义字体

[英]Custom fonts in Interface Builder

So we're in 2014, is there any way to set custom fonts within Interface Builder yet? 所以我们在2014年,有没有办法在Interface Builder中设置自定义字体? Ie don't do it programmatically, except for "Fonts provided by application" in the app's plist. 即不要以编程方式执行,除了应用程序的plist中的“应用程序提供的字体”。

Yes, Marrius is right. 是的,Marrius是对的。 In Xcode 6, you neither need to use extra software nor to set Font in Code files. 在Xcode 6中,您既不需要使用额外的软件也不需要在代码文件中设置字体。 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. “界面”构建器将在“自定义字体列表”中显示添加的字体。

And the most amazing thing is, xcode 6 shows the applied font instantly in IB. 最令人惊奇的是,xcode 6在IB中立即显示应用的字体。 This is the great addition by Apple. 这是Apple的重要补充。

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中添加此键“应用程序提供的字体”,并提供字体文件名以查看设备中的效果。

In Xcode 6, we have custom fonts available in interface builder. 在Xcode 6中,我们在界面构建器中提供了自定义字体。

No need for extra software. 无需额外的软件。 Thank you Apple! 谢谢Apple!

In Xcode 6, just add the ttf file in your project and use it in storyboard through custom fonts. 在Xcode 6中,只需在项目中添加ttf文件,并通过自定义字体在故事板中使用它。 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. 如果你直接想在你的代码中使用它而不在storyboard中使用它,那么你必须在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. 就在projectName-Info.plist中的行</dict>之前。

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

Looks like someone worked on it. 看起来有人在研究它。 You can have a look at MoarFonts : 你可以看一下MoarFonts

MoarFonts MoarFonts

Use custom fonts for your iOS projects directly in Interface Builder, the WYSIWYG way 直接在Interface Builder中使用自定义字体为您的iOS项目,即WYSIWYG方式

by Cédric Luthi “ 0xced 作者: CédricLuthi0xced

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. 从iOS 3.2开始,您可以通过添加UIAppFonts Info.plist密钥在iOS应用中使用自定义字体。 Unfortunately, custom fonts are not available when editing your xib files in Interface Builder. 遗憾的是,在Interface Builder中编辑xib文件时,自定义字体不可用。 MoarFonts makes your custom fonts available right within Interface Builder. MoarFonts使您的自定义字体在Interface Builder中可用。

MoarFonts is compatible with both Xcode 4 and Xcode 5. MoarFonts兼容Xcode 4和Xcode 5。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM