Tuesday, 18 March 2014

iPhone Developement: Get list of Fonts available on iPhone devices

Fonts are the important part of iPhone app development. To decorate text shown in our application, we can use wide variety of fonts available.
You can give font to a label or other text display control by simply writing

friendNameLabel.font = [UIFont systemFontOfSize:14.0];

It will give system font to our label.

We can also give other fonts to our label. For this we have to use a different method

To get the fonts associated with a font family, you can use fontNamesForFamilyName method to get a list of them in an array

 NSArray *fontArrays = [UIFont fontNamesForFamilyName:@"Verdana"];
  NSLog(@"FOnt array == %@",fontArrays);

The above code will give you output as shown in below picture

Now you can give bold font to your label
friendNameLabel.font=[UIFont fontWithName:@"Verdana-Bold" size:14.0];

To get all font family names installed on your device you can use

   NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
    NSArray *fontNames;
    NSInteger indFamily, indFont;
    for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
        NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
        fontNames = [[NSArray alloc] initWithArray:
                     [UIFont fontNamesForFamilyName:
                      [familyNames objectAtIndex:indFamily]]];
        for (indFont=0; indFont<[fontNames count]; ++indFont)
            NSLog(@"Font name: %@", [fontNames objectAtIndex:indFont]);
        [fontNames release];
    [familyNames release];

No comments:
Write comments