菜鸟教程小白 发表于 2022-12-11 19:23:47

ios - Xcode 中的自定义字体不起作用


                                            <p><p>添加自定义字体作为教程建议 <a href="https://medium.com/yay-its-erica/how-to-import-fonts-into-xcode-swift-3-f0de7e921ef8" rel="noreferrer noopener nofollow">here</a> .</p>

<ul>
<li>字体位于“构建阶段”->“捆绑资源”中</li>
<li>字体名称在您的 plist 中</li>
</ul>

<p> <a href="/image/eKs3X.png" rel="noreferrer noopener nofollow"><img src="/image/eKs3X.png" alt="enter image description here"/></a> </p>

<p> <a href="/image/Y7xp6.png" rel="noreferrer noopener nofollow"><img src="/image/Y7xp6.png" alt="enter image description here"/></a> </p>

<p> <a href="/image/0wgRq.png" rel="noreferrer noopener nofollow"><img src="/image/0wgRq.png" alt="enter image description here"/></a> </p>

<p>但无论是从 Stroyboard 还是从代码,我都无法设置 <code>UILabel</code> 的字体。我错过了什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>请仔细阅读 <a href="https://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/#findfontname" rel="noreferrer noopener nofollow">article</a> . </p>

<blockquote>
<p>Step 5: Find the name of the font</p>

<p>This is a common pitfall for many people trying to include custom
fonts into their iOS app. This was something that eluded me before as
well and it’s the fact that when you specify which font you want to
use, you’re not specifying the file name but rather, the font name.
The tricky part is that the font name may not be what you expect. It
could be very different than any of the visible font names that you
can see.</p>

<p>So in order to easily find the name of the font that you want to use,
you can output something to the console window and see for yourself.</p>
</blockquote>

<p>您可以使用此代码为开发人员打印所​​有可用字体的名称:</p>

<p><code>在 UIFont.familyNames {
   打印(“\(家庭)”)
   对于 UIFont.fontNames(forFamilyName: family){
         打印(“==\(名称)”)
   }
}
</code></p>

<p>它会产生这样的输出:</p>

<p> <a href="/image/lTaym.png" rel="noreferrer noopener nofollow"><img src="/image/lTaym.png" alt="console output"/></a> </p>

<p>找到你的并将其用于:</p>

<p><code>label.font = UIFont(name: "SFProText-Heavy", size: 14.0)
</code></p>

<p>要向界面生成器添加自定义字体,请从 <code>Spotlight Search</code> 中打开 <code>Font Book</code> 并将您的字体拖放到那里</p>

<p> <a href="/image/Akdbi.png" rel="noreferrer noopener nofollow"><img src="/image/Akdbi.png" alt="enter image description here"/></a> </p>

<p> <a href="/image/YYrXr.png" rel="noreferrer noopener nofollow"><img src="/image/YYrXr.png" alt="enter image description here"/></a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Xcode 中的自定义字体不起作用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47614047/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47614047/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Xcode 中的自定义字体不起作用