Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: set font size of UILabel Programmatically

Tags:

ios

uilabel

I'm trying to set the font size of a UILabel. No matter what value I put though the text size doesn't seem to change. Here's the code I'm using.

[self setTitleLabel:[[UILabel alloc] initWithFrame:CGRectMake(320.0,0.0,428.0,50.0)]]; [[self contentView] addSubview:[self titleLabel]]; UIColor *titlebg = [UIColor clearColor]; [[self titleLabel] setBackgroundColor:titlebg]; [[self titleLabel] setTextColor:[UIColor blackColor]]; [[self titleLabel] setFont:[UIFont fontWithName:@"System" size:36]]; 
like image 292
LoneWolfPR Avatar asked Jul 10 '13 16:07

LoneWolfPR


People also ask

How do I change font size in UIButton?

To set a different font on UIButton programmatically you will need to create a new instance of UIFont object. The initializer of UIFont accepts two arguments: name and size. where the “GillSans-Italic” is a font name you want to set.

How do I change the size of labels in Xcode?

You can set the Minimum Font Scale or size in Storyboard/Xib when you set it up in IB under the Attributes inspector. I prefer scale, as it is better at fitting longer text on iPhone 4/5/iPod touches. If you set the size, you can get cut off earlier than with scale.


1 Answers

Try [UIFont systemFontOfSize:36] or [UIFont fontWithName:@"HelveticaNeue" size:36] i.e. [[self titleLabel] setFont:[UIFont systemFontOfSize:36]];

like image 89
JohnVanDijk Avatar answered Oct 11 '22 22:10

JohnVanDijk