我需要通过编程方式设置UIButton标题UILabel的字体大小。
当前回答
斯威夫特4
button.titleLabel?.font = UIFont(name: "Font_Name_Here", size: Font_Size_Here)
objective - c
[button.titleLabel setFont:[UIFont fontWithName:@“Font_Name_Here” size: Font_Size_Here]];
例子:
Font_Name = "Helvetica"
Font_Size = 16.0
希望能有所帮助。
其他回答
objective - c:
[button.titleLabel setFont: [button.titleLabel.font fontWithSize: sizeYouWant]];
迅速:
button.titleLabel?.font = button.titleLabel?.font.fontWithSize(sizeYouWant)
只会改变字体大小。
斯威夫特3:
myButton.titleLabel?.font = myButton.titleLabel?.font.withSize(40)
button.titleLabel.font = [UIFont systemFontOfSize:size];
应该帮助
斯威夫特5。
uiButton.titleLabel?.font = UIFont.systemFont(ofSize: 32)
支持UIButton中的辅助功能
extension UILabel
{
func scaledFont(for font: UIFont) -> UIFont {
if #available(iOS 11.0, *) {
return UIFontMetrics.default.scaledFont(for: font)
} else {
return font.withSize(scaler * font.pointSize)
}
}
func customFontScaleFactor(font : UIFont) {
translatesAutoresizingMaskIntoConstraints = false
self.adjustsFontForContentSizeCategory = true
self.font = FontMetrics.scaledFont(for: font)
}
}
你可以按钮字体现在。
UIButton().titleLabel?.customFontScaleFactor(font: UIFont.systemFont(ofSize: 12))
推荐文章
- iPhone上UIView和UILabels的渐变
- keychain上的分发证书中缺少私钥
- 在实现API时,我如何避免在块中捕获自我?
- 如何创建一个Swift Date对象?
- Xcode 4在目标设备上说“finished running <my app>”——什么都没有发生
- 从另一个应用程序打开设置应用程序
- 快速提取正则表达式匹配
- 如何应用梯度的背景视图的iOS Swift应用程序
- 图书馆吗?静态的?动态吗?或框架?另一个项目中的项目
- 如何用SwiftUI调整图像大小?
- Xcode 6 gitignore文件应该包括什么?
- 如何在iPhone/iOS上删除电话号码的蓝色样式?
- 检测视网膜显示
- 如何在UIImageView中动画图像的变化?
- 如何从iPhone访问SOAP服务