简体   繁体   English

更改uibutton的文本大小不起作用

[英]Changing text size of uibutton doesn't work

I've created a button in story board and I'm trying to set font size and font style programmatically as follows: 我在故事板上创建了一个按钮,我正在尝试以编程方式设置字体大小字体样式 ,如下所示:

_login.titleLabel.textColor = [UIColor whiteColor];
_login.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[_login.titleLabel setFont:[UIFont boldSystemFontOfSize:13.f]];
[_login setBackgroundColor:[UIColor purpleColor]];

But the button text size remains the same. 但按钮文本大小保持不变。 Am I missing something? 我错过了什么吗?

 button.titleLabel.font = [UIFont systemFontOfSize:size];

这应该工作

Swift 3.1

_loginButton.titleLabel?.font = _loginButton.titleLabel?.font.withSize(yourSize)

objective c: both will work perfectly 目标c:两者都能完美运作

(first) (第一)

[_loginButton.titleLabel setFont: [_loginButton.titleLabel.font fontWithSize: size]];

(second) (第二)

_loginButton.titleLabel.font =[UIFont boldSystemFontOfSize:20.f];

swift: if anybody want in swift 斯威夫特:如果有人想要迅速

_loginButton.titleLabel?.font = _loginButton.titleLabel?.font.fontWithSize(sizeYouWant)

for more datails you can verify: Set UIButton title UILabel font size programmatically 您可以验证更多数据:以编程方式设置UIButton标题UILabel字体大小

Try this: 试试这个:

[_login.titleLabel setFont:[UIFont systemFontOfSize:10]

Option A : 选项A

[_login.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0f*Ratio]];

试试这段代码:

[_login.titleLabel setFont:[_login.titleLabel.font fontWithSize: yourSize]];

试试这个,使用yourButton.titleLabel.font

_login.titleLabel.font = [UIFont boldSystemFontOfSize:13.0f];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM