Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the font of a label programmatically? [duplicate]

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?

like image 367
iHackerMe Avatar asked Sep 20 '12 09:09

iHackerMe


People also ask

How do you change the font of text in Javascript?

To change or set a font style for certain text, the fontFamily CSS property needs to be changed. The fontFamily property sets or returns a list of font-family names for text in an element. To change the font style by option dropdown: The font values can be passed in option tags using option value.

Can you change font in C#?

A form with a label and a button 'Options'. By clicking the button a new form opens with 2 radio buttons 'Font1' and 'Font2', and two buttons 'Apply' and 'Cancel'. Upon selecting one of the radio buttons and clicking 'Apply' will make the label on the first form change the font face.

How do I change font size in programmatically in Swift?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


1 Answers

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]];
like image 117
Paresh Navadiya Avatar answered Sep 30 '22 12:09

Paresh Navadiya