5

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?

StepUp
  • 36,391
  • 15
  • 88
  • 148
  • 4
    First verify for IBOutlet part. Your button should not be nil when try to change its property. – Apurv Apr 29 '16 at 05:37
  • 1
    Someone gave you a -1 so I gave you a +1, because I don't think this is a -1 question. You have already got a good answer. – J. Lopes Apr 29 '16 at 13:51

6 Answers6

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

This should work

ios
  • 955
  • 1
  • 12
  • 35
3

Swift 3.1

_loginButton.titleLabel?.font = _loginButton.titleLabel?.font.withSize(yourSize)
Craig P
  • 477
  • 6
  • 12
2

Try this:

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

Option A:

[_login.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0f*Ratio]];
Mr. Bond
  • 427
  • 1
  • 4
  • 18
1

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

Community
  • 1
  • 1
UdayM
  • 1,725
  • 16
  • 34
0

TRy this code:

[_login.titleLabel setFont:[_login.titleLabel.font fontWithSize: yourSize]];
Mr. Bond
  • 427
  • 1
  • 4
  • 18
-1

Try this, Use yourButton.titleLabel.font

_login.titleLabel.font = [UIFont boldSystemFontOfSize:13.0f];
Sheereen S
  • 1,292
  • 10
  • 18