ios - 如何在按钮Objective-C的标题上设置字体
<p><p>我正在尝试在按钮上设置标题的字体。我从 Apples Documentation on Fonts in Objective C 阅读并尝试实现但它没有更改字体。我也试过这个帖子... <a href="https://stackoverflow.com/questions/11443283/setting-uibutton-font" rel="noreferrer noopener nofollow">setting UIButton font</a> .我的字体来自谷歌字体...“Nunito-Black.tff”</p>
<p>下面是我的代码,</p>
<pre><code>- (void)addHeaderButton {
_headerButton = ;
self.headerButton.frame = self.bounds;
self.headerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
forState:UIControlStateNormal];
self.headerButton.titleLabel.font = ;
//];
;
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>以下是在您的应用中添加自定义字体的步骤。</p>
<p><strong>步骤:1</strong></p>
<p>使用 <strong>UIAppFonts</strong>(<em>应用程序提供的字体</em>)键将您的自定义字体添加到您的应用程序包和 <code>Info.plist</code>。如下图所示</p>
<p> <a href="/image/rFyDJ.png" rel="noreferrer noopener nofollow"><img src="/image/rFyDJ.png" alt="enter image description here"/></a> </p>
<p><strong>步骤:2</strong></p>
<p>使用以下代码段获取自定义添加的字体名称</p>
<p>[<em>Objective-C</em>]</p>
<pre><code>for (NSString *familyName in ){
NSLog(@"Family name: %@", familyName);
for (NSString *fontName in ) {
NSLog(@"--Font name: %@", fontName);
}
}
</code></pre>
<p>[<em> swift- 3</em>]</p>
<pre><code>for family in UIFont.familyNames {
print("\(family)")
for name in UIFont.fontNames(forFamilyName: family) {
print(" \(name)")
}
}
</code></pre>
<p><strong>步骤:3</strong></p>
<p>从上面的代码片段中获取字体的名称,获取名称后,您可以将字体名称设置为您尊重的元素,如下所示</p>
<pre><code>self.headerButton.titleLabel.font = ;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在按钮Objective-C的标题上设置字体,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45332900/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45332900/
</a>
</p>
页:
[1]