ios - 设置 UIButton 的 titleLabel.font 属性不起作用

标签 ios objective-c ios7 uibutton uifont

在目前使用 iOS 7 的过程中,我试图增加 UIButton 的 titleLabel 的字体大小。我是这样做的,

[[_centerButton titleLabel] setFont:[UIFont boldSystemFontOfSize:28.0]];

然而这并没有做任何事情。每次我用不同的大小编译时,字体总是保持不变。即使我完全删除该行,字体也保持不变。显然它坚持默认大小。

如何增加 UIButton 标题的字体大小?

最佳答案

使用 Xcode 13,我必须将 Interface 上的 Style 属性从 Plain 更改为 Default生成器

enter image description here

然后在设置标题后,我终于可以毫无问题地以编程方式更改字体:

button.setTitle("The title", for: .normal)
button.titleLabel?.font = UIFont(name: "Montserrat-SemiBold", size: 15)

关于ios - 设置 UIButton 的 titleLabel.font 属性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19339948/

相关文章:

objective-c - 如何在 UITextview 中同时隐藏键盘并以编程方式选择文本?

objective-c - SKStoreProductViewController 给出 Domain=SKErrorDomain Code=5 iOS7 错误

ios - 在 iOS 8/iPhone 6 上获取像素数据

ios - AFNetworking 1.3.1 图像下载responseObject 为nil

ios - 使用 XCUITest 设置 UI 自动化测试的可访问性标识符

iphone - didFinishLaunchingWithOptions 有什么作用?

ios - 核心数据和 NSFetchedResultsController : ignoring fields in controllerDidChangeContent

ios - 如何修复 ipad 中的方向错误?

iphone - 我的功能合并 2 张图片适用于 iOS 6,但现在返回的是 ios 7 的空图片

ios - 哪些类不符合 KVO 标准?