Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the font size and font name of a UILabel?

Tags:

ios

I have a UILabel which I set a font size and a font name with Interface Builder. Now I have to read the values of both in my ViewController.

How can I do this?

like image 220
Tim Avatar asked Feb 01 '11 17:02

Tim


People also ask

How do I change the font size in UILabel?

Change Font And Size Of UILabel In StoryboardSelect the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


2 Answers

Add a property to your view controller's .h file:

@property (nonatomic, retain) IBOutlet UILabel *label; 

Link the label to this IBOutlet under "File's Owner" outlets in Interface Builder. If not using ARC, make sure you release it in -dealloc

- (void)dealloc {     [self.label release];     [super dealloc]; } 

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

NSString *fontName = self.label.font.fontName; CGFloat fontSize = self.label.font.pointSize; 
like image 90
Ned Avatar answered Oct 03 '22 10:10

Ned


Swift:

var currentFontSize = button.titleLabel?.font.pointSize 
like image 27
Esqarrouth Avatar answered Oct 03 '22 09:10

Esqarrouth