简体   繁体   English

xcode 7和自适应布局中的自定义字体

[英]custom fonts in xcode 7 and adaptive layout

So I'm running into a problem with custom fonts using Xcode 7 with adaptive layout. 所以我在使用具有自适应布局的Xcode 7时遇到自定义字体的问题。 It's kind of strange. 有点奇怪 Basically, the custom fonts appear in the storyboards and preview but do not display on the actual devices when I run the app. 基本上,自定义字体会显示在情节提要中并进行预览,但在运行应用程序时不会显示在实际设备上。

i have this problem just with custom fonts, I have the fonts correctly installed. 我只有自定义字体才有此问题,我已经正确安装了字体。 That is not the problem. 那不是问题。 I have checked that repeatedly. 我已经反复检查过。 The font shows up in the label's attributes inspector. 字体显示在标签的属性检查器中。 I select the font from the list of custom fonts from the attributes inspector. 我从属性检查器的自定义字体列表中选择字体。 The font appears in the storyboard. 字体出现在情节提要中。 But when I run... no custom 但是当我跑步...没有习惯

Make sure that fonts are properly added in the Xcode project and include them in Info.plist file. 确保在Xcode项目中正确添加了字体,并将其包含在Info.plist文件中。

<key>UIAppFonts</key>
<array>
    <string>Colaborate-Bold.otf</string>
    <string>SourceSansPro-Regular.otf</string>
    <string>SourceSansPro-Semibold.otf</string>
</array>

在此处输入图片说明

Here is the link about Common Mistakes with Custom Fonts: 这是有关自定义字体常见错误的链接:

http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

Hope it will work for you. 希望它对您有用。

It sounds like your fonts aren't being bundled with your app. 听起来您的字体没有与您的应用捆绑在一起。 You've already ensured that the fonts are installed in your project , but you also have to make sure that they're among the resources that are included for your build target. 您已经确保在项目中安装了字体,但是还必须确保字体是构建目标所包含的资源之一。

I solve this problem with building a custom UI Elements 我通过构建自定义UI元素解决了这个问题

@IBDesignable class ExUITextField: UITextField {

@IBInspectable var fontName: String = "yourCustomFont" {
    didSet {
        self.font = UIFont(name: fontName, size:self.font!.pointSize)
    }
}

override func layoutSubviews() {
    super.layoutSubviews()
    self.font = UIFont(name: fontName, size:self.font!.pointSize)
}

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

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