iOS: set font size of UILabel Programmatically
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]];
Solution 1:
Try [UIFont systemFontOfSize:36]
or [UIFont fontWithName:@"HelveticaNeue" size:36]
i.e. [[self titleLabel] setFont:[UIFont systemFontOfSize:36]];
Solution 2:
Objective-C:
[label setFont: [label.font fontWithSize: sizeYouWant]];
Swift:
label.font = label.font.fontWithSize(sizeYouWant)
just changes font size of a UILabel.