UIFont Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Declared in
UIFont.h
UIInterface.h
Related sample code

Overview

The UIFont class provides the interface for getting and setting font information. The class provides you with access to the font’s characteristics and also provides the system with access to the font’s glyph information, which is used during layout. You use font objects by passing them to methods that accept them as a parameter.

You do not create UIFont objects using the alloc and init methods. Instead, you use class methods of UIFont to look up and retrieve the desired font object. These methods check for an existing font object with the specified characteristics and return it if it exists. Otherwise, they create a new font object based on the desired font characteristics.

Font objects are immutable and so it is safe to use them from multiple threads in your app.

Tasks

Creating Arbitrary Fonts

Creating System Fonts

Getting the Available Font Names

Getting Font Name Attributes

Getting Font Metrics

Getting System Font Information

Properties

ascender

The top y-coordinate, offset from the baseline, of the receiver’s longest ascender. (read-only)

@property(nonatomic, readonly) CGFloat ascender
Discussion

The ascender value is measured in points.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

capHeight

The receiver’s cap height information. (read-only)

@property(nonatomic, readonly) CGFloat capHeight
Discussion

This value measures (in points) the height of a capital character.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

descender

The bottom y-coordinate, offset from the baseline, of the receiver’s longest descender. (read-only)

@property(nonatomic, readonly) CGFloat descender
Discussion

The descender value is measured in points. This value may be positive or negative. For example, if the longest descender extends 2 points below the baseline, this method returns -2.0 .

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIFont.h

familyName

The font family name. (read-only)

@property(nonatomic, readonly, retain) NSString *familyName
Discussion

A family name is a name such as Times New Roman that identifies one or more specific fonts. The value in this property is intended for an application’s internal usage only and should not be displayed.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIFont.h

fontName

The font face name. (read-only)

@property(nonatomic, readonly, retain) NSString *fontName
Discussion

The font name is a name such as HelveticaBold that incorporates the family name and any specific style information for the font. The value in this property is intended for an application’s internal usage only and should not be displayed.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

lineHeight

The height of text lines (measured in points). (read-only)

@property(nonatomic,readonly) CGFloat lineHeight
Availability
  • Available in iOS 4.0 and later.
Declared In
UIFont.h

pointSize

The receiver’s point size, or the effective vertical point size for a font with a nonstandard matrix. (read-only)

@property(nonatomic, readonly) CGFloat pointSize
Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

xHeight

The x-height of the receiver. (read-only)

@property(nonatomic, readonly) CGFloat xHeight
Discussion

This value measures (in points) the height of the lowercase character "x".

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

Class Methods

boldSystemFontOfSize:

Returns the font object used for standard interface items that are rendered in boldface type in the specified size.

+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize
Parameters
fontSize

The size (in points) to which the font is scaled. This value must be greater than 0.0.

Return Value

A font object of the specified size.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

buttonFontSize

Returns the standard font size used for buttons.

+ (CGFloat)buttonFontSize
Return Value

The standard button font size in points.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIInterface.h

familyNames

Returns an array of font family names available on the system.

+ (NSArray *)familyNames
Return Value

An array of NSString objects, each of which contains the name of a font family.

Discussion

Font family names correspond to the base name of a font, such as Times New Roman. You can pass the returned strings to the fontNamesForFamilyName: method to retrieve a list of font names available for that family. You can then use the corresponding font name to retrieve an actual font object.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIFont.h

fontNamesForFamilyName:

Returns an array of font names available in a particular font family.

+ (NSArray *)fontNamesForFamilyName:(NSString *)familyName
Parameters
familyName

The name of the font family. Use the familyNames method to get an array of the available font family names on the system.

Return Value

An array of NSString objects, each of which contains a font name associated with the specified family.

Discussion

You can pass the returned strings as parameters to the fontWithName:size: method to retrieve an actual font object.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

fontWithName:size:

Creates and returns a font object for the specified font name and size.

+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize
Parameters
fontName

The fully specified name of the font. This name incorporates both the font family name and the specific style information for the font.

fontSize

The size (in points) to which the font is scaled. This value must be greater than 0.0.

Return Value

A font object of the specified name and size.

Discussion

You can use the fontNamesForFamilyName: method to retrieve the specific font names for a given font family.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

italicSystemFontOfSize:

Returns the font object used for standard interface items that are rendered in italic type in the specified size.

+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize
Parameters
fontSize

The size (in points) to which the font is scaled. This value must be greater than 0.0.

Return Value

A font object of the specified size.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIFont.h

labelFontSize

Returns the standard font size used for labels.

+ (CGFloat)labelFontSize
Return Value

The standard label font size in points.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UIInterface.h

smallSystemFontSize

Returns the size of the standard small system font.

+ (CGFloat)smallSystemFontSize
Return Value

The standard small system font size in points.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIInterface.h

systemFontOfSize:

Returns the font object used for standard interface items in the specified size.

+ (UIFont *)systemFontOfSize:(CGFloat)fontSize
Parameters
fontSize

The size (in points) to which the font is scaled. This value must be greater than 0.0.

Return Value

A font object of the specified size.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

systemFontSize

Returns the size of the standard system font.

+ (CGFloat)systemFontSize
Return Value

The standard system font size in points.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIInterface.h

Instance Methods

fontWithSize:

Returns a font object that is the same as the receiver but which has the specified size instead.

- (UIFont *)fontWithSize:(CGFloat)fontSize
Parameters
fontSize

The desired size (in points) of the new font object. This value must be greater than 0.0.

Return Value

A font object of the specified size.

Availability
  • Available in iOS 2.0 and later.
Declared In
UIFont.h

Did this document help you? Yes It's good, but... Not helpful...