iOS: set font size of UILabel Programmatically

LoneWolfPR picture LoneWolfPR · Jul 10, 2013 · Viewed 156.6k times · Source

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

Answer

JohnVanDijk picture JohnVanDijk · Jul 10, 2013

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