Ios 如何设置按钮Objective-C标题的字体
我正在尝试设置按钮标题的字体。我阅读了苹果公司关于Objective C中字体的文档,并尝试实现,但没有改变字体。我也试过这个帖子。我的字体来自谷歌字体…“Nunito Black.tff” 下面是我的代码Ios 如何设置按钮Objective-C标题的字体,ios,objective-c,fonts,Ios,Objective C,Fonts,我正在尝试设置按钮标题的字体。我阅读了苹果公司关于Objective C中字体的文档,并尝试实现,但没有改变字体。我也试过这个帖子。我的字体来自谷歌字体…“Nunito Black.tff” 下面是我的代码 - (void)addHeaderButton { _headerButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.headerButton.frame = self.bounds; self.h
- (void)addHeaderButton {
_headerButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.headerButton.frame = self.bounds;
self.headerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self.headerButton setTitleColor:[UIColor colorWithRed:(0.0/255.0) green:(51.0/255.0) blue:(102.0/255.0) alpha:(1.0)] forState:UIControlStateNormal];
self.headerButton.titleLabel.font = [UIFont fontWithName:@"Nunito-Black" size:25];
//[self.headerButton setFont:[UIFont systemFontOfSize:25]];
[self.headerButton addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.headerButton];
}
您需要将字体的确切名称添加到“应用程序提供的字体”下的Info.plist中。以下是将自定义字体添加到应用程序中的步骤 步骤:1 使用UIAppFonts(应用程序提供的字体)键将自定义字体添加到应用程序包和
Info.plist
。如下图所示
步骤:2
使用下面的代码段获取自定义添加的字体名称
[目标-C]
[Swift-3]
步骤:3
从上面的代码片段中获取字体名称,获取名称后,您可以将字体名称设置为您所关注的元素,如下所示
self.headerButton.titleLabel.font = [UIFont fontWithName:@"Nunito-Black" size:25];
它是否至少适用于
UILabel
?是[UIFont fontWithName:@“Nunito Black”大小:25]代码>无?您是否已将字体添加到项目中?了解。另外,请参阅@KimRiegel的列表,确保您的字体包含在目标和Info.plist中的“应用程序提供的字体”键下。还要考虑到您必须指定字体名称,而不是文件名。您的self.headerButton.frame=self.bounds;为headerButton提供了合适的框架?@albertamg不得不将它们添加到info.plist,感谢您提供的链接,我学到了很多!
for family in UIFont.familyNames {
print("\(family)")
for name in UIFont.fontNames(forFamilyName: family) {
print(" \(name)")
}
}
self.headerButton.titleLabel.font = [UIFont fontWithName:@"Nunito-Black" size:25];