简体   繁体   中英

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

(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

Try this:

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

Option 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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