8

Possible Duplicate:
Setting UILabel - Font through code - generates error - iPhone

I want to know is there any way to set the font of a label programmatically as I need to change the font in my app when a condition is set true. How can I do so using Apple's variety of fonts?

Community
  • 1
  • 1
iHackerMe
  • 581
  • 2
  • 5
  • 17
  • See [this](http://stackoverflow.com/q/1380490/730701) and [this](http://stackoverflow.com/q/1302833/730701). – Adam Sep 20 '12 at 09:50
  • take a quick look at **[UILabel Class Reference](http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UILabel_Class/Reference/UILabel.html)**, I hope I did't say any new things with it... – holex Sep 20 '12 at 09:57

4 Answers4

17

Make yourself a list of available fonts:

for( NSString *strFamilyName in [UIFont familyNames] ) {
  for( NSString *strFontName in [UIFont fontNamesForFamilyName:strFamilyName] ) {
    NSLog(@"%@", strFontName);
  }
}

Now set Font like this:

 [yourLabel setFont:[UIFont fontWithName:@"your font name here" size:fontsizehere]];

EDIT :

For example like this:

 [yourLabel setFont:[UIFont fontWithName:@"Arial" size:15]];
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
1

Here use this code.

[labelname setFont:[UIFont fontWithName:@"American Typewriter" size:18]];
IronManGill
  • 7,222
  • 2
  • 31
  • 52
1

Set like this

UIFont *font = [UIFont fontWithName:@"MyFont" size:20];
    [label setFont:font];
Senthilkumar
  • 2,471
  • 4
  • 30
  • 50
1

//set label

label.font = [UIFont fontWithName:@"Calibri" size:15];

//set label color

label.textColor = [UIColor redColor]; 

//set label colr if you have RGB value

label.textColor = [UIColor colorWithRed:180.0/255.0 green:6.0/255.0 blue:47.0/255.0 alpha:1.0];
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74