user1960169
user1960169

Reputation: 3653

How to get the current font size of an UILabel

I have adjusted the UILabel font size according to the width in this way.

[btnPending.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:15]];
[btnPending setBackgroundColor:[UIColor clearColor]];
btnPending.titleLabel.adjustsFontSizeToFitWidth = YES;
btnPending.titleLabel.numberOfLines = 1;
btnPending.titleLabel.lineBreakMode = NSLineBreakByClipping;
[_vwTabBtnParent addSubview:btnPending];

And its working fine. But now I want to get the current font size of that UILabel. How can I do this in objective-c.

Please help me, Thanks

Upvotes: 3

Views: 4278

Answers (2)

Ronak Chaniyara
Ronak Chaniyara

Reputation: 5435

Try below method:

[label.text sizeWithFont:label.font
             minFontSize:label.minimumFontSize
          actualFontSize:&actualFontSize
                forWidth:label.bounds.size.width
           lineBreakMode:label.lineBreakMode];

Note: Deprecated in iOS 7 with no alternative.

Upvotes: 0

Kishore Kumar
Kishore Kumar

Reputation: 4375

Then to get the font name and size all you need is

NSString *fontName = self.label.font.fontName;
CGFloat fontSize = self.label.font.pointSize;

Upvotes: 4

Related Questions