Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel: how do you set the font size?

How do you set the font size from a UILabel?

My code:

UILabel *myView = [[UILabel alloc] initWithFrame:RectFrame]; [myView setBackgroundColor:[UIColor blueColor]]; [myView setText:[NSString stringWithFormat:@" A"]]; [myView setFont:[12] ]; <--- Error [self.view addSubview:myView]; 
like image 950
jdl Avatar asked Jun 09 '11 14:06

jdl


People also ask

How do I increase font size in Objective C?

You can just make use of the same function that you call in setFont which is [UIFont fontWithName:size:] .

How do I change font size in Visual Basic label?

Instead just go to the properties of whatever you're trying to change the font size of, and go to the font property. Click on the 3 dots (...) and a box will open. In that box, you can change the font and its size too.


2 Answers

[myView setFont:[UIFont systemFontOfSize:12]]; 

or

[myView setFont:[UIFont boldSystemFontOfSize:12]]; 

or for font family

[myView setFont:[UIFont fontWithName:@"Helvetica" size:12]]; 
like image 198
CristiC Avatar answered Oct 04 '22 11:10

CristiC


If your UILabel's font is defined in IB storyboard and you just want to increase size then this will work, worked for me ;)

[_label setFont: [_label.font fontWithSize: sizeYouWant]]; 

Or

[self.label setFont: [self.label.font fontWithSize: sizeYouWant]]; 

Another method as others says also worked:

[_label setFont:[UIFont systemFontOfSize:13.0]]; 
like image 21
karan Avatar answered Oct 04 '22 12:10

karan