有没有办法将自定义字体添加到 Xcode 以从故事板中可用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17278395/
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-09-15 03:32:14  来源:igfitidea点击:

Is there a way to add custom fonts to Xcode to be available from a storyboard?

xcodeuilabelcustomizationuistoryboarduifont

提问by Alex Stone

I know how to add custom font files to be shipped with an iOS app. I can then customize the label font from code using code like this :

我知道如何添加要随 iOS 应用程序一起提供的自定义字体文件。然后我可以使用如下代码从代码中自定义标签字体:

UIFont* font = [UIFont fontWithName:@"League Gothic" size:42];
self.topLabel.font = font;

My concern is that such customization will "infect" all of the project and may require some significant rework later on. Is there a way to include a font file into xCode itself, so it recognizes it and lets me select it from the storyboard font control?

我担心这种定制会“感染”所有项目,并且可能需要在以后进行一些重大的返工。有没有办法将字体文件包含到 xCode 本身中,以便它识别它并让我从故事板字体控件中选择它?

回答by Rajat

You can find the answer to this question over here

你可以在这里找到这个问题的答案

Designing labels/text views with custom fonts in Interface Builder

在 Interface Builder 中使用自定义字体设计标签/文本视图

You can find a link regarding the same topic here

您可以在此处找到有关同一主题的链接

http://www.abdus.me/ios-programming-tips/set-custom-fonts-in-interface-builder/

http://www.abdus.me/ios-programming-tips/set-custom-fonts-in-interface-builder/

Hope this helps you.

希望这对你有帮助。

回答by redent84

Another way to achieve it without having to relay on exposing IBOutlets or adding external libraries is using categories and user defined runtime attributes from Storyboard or Interface Builder.

另一种无需依赖暴露IBOutlet或添加外部库即可实现它的方法是使用来自 Storyboard 或 Interface Builder 的类别和用户定义的运行时属性。

That way you can define your fonts in Storyboard or IB like this:

这样你就可以像这样在 Storyboard 或 IB 中定义你的字体:

Runtime Attributes

运行时属性

You can get the code required for the categories from this response.

您可以从此响应中获取类别所需的代码。