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 |
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
-
familyNameproperty -
fontNameproperty
Getting Font Metrics
-
pointSizeproperty -
ascenderproperty -
descenderproperty -
capHeightproperty -
xHeightproperty -
lineHeightproperty -
leadingproperty Deprecated in iOS 4.0
Getting System Font Information
Properties
ascender
The top y-coordinate, offset from the baseline, of the receiver’s longest ascender. (read-only)
Discussion
The ascender value is measured in points.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
UIFont.hcapHeight
The receiver’s cap height information. (read-only)
Discussion
This value measures (in points) the height of a capital character.
Availability
- Available in iOS 2.0 and later.
Declared In
UIFont.hdescender
The bottom y-coordinate, offset from the baseline, of the receiver’s longest descender. (read-only)
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.
See Also
Declared In
UIFont.hfamilyName
The font family name. (read-only)
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.
Declared In
UIFont.hfontName
The font face name. (read-only)
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.hlineHeight
The height of text lines (measured in points). (read-only)
Availability
- Available in iOS 4.0 and later.
Declared In
UIFont.hpointSize
The receiver’s point size, or the effective vertical point size for a font with a nonstandard matrix. (read-only)
Availability
- Available in iOS 2.0 and later.
Declared In
UIFont.hxHeight
The x-height of the receiver. (read-only)
Discussion
This value measures (in points) the height of the lowercase character "x".
Availability
- Available in iOS 2.0 and later.
Declared In
UIFont.hClass Methods
boldSystemFontOfSize:
Returns the font object used for standard interface items that are rendered in boldface type in the specified size.
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.hbuttonFontSize
Returns the standard font size used for buttons.
Return Value
The standard button font size in points.
Availability
- Available in iOS 2.0 and later.
Declared In
UIInterface.hfamilyNames
Returns an array of font family names available on the system.
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.
See Also
Declared In
UIFont.hfontNamesForFamilyName:
Returns an array of font names available in a particular font family.
Parameters
- familyName
The name of the font family. Use the
familyNamesmethod 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.
See Also
Declared In
UIFont.hfontWithName:size:
Creates and returns a font object for the specified font name and size.
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.
See Also
Declared In
UIFont.hitalicSystemFontOfSize:
Returns the font object used for standard interface items that are rendered in italic type in the specified size.
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.hlabelFontSize
Returns the standard font size used for labels.
Return Value
The standard label font size in points.
Availability
- Available in iOS 2.0 and later.
Declared In
UIInterface.hsmallSystemFontSize
Returns the size of the standard small system font.
Return Value
The standard small system font size in points.
Availability
- Available in iOS 2.0 and later.
Declared In
UIInterface.hsystemFontOfSize:
Returns the font object used for standard interface items in the specified size.
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.hsystemFontSize
Returns the size of the standard system font.
Return Value
The standard system font size in points.
Availability
- Available in iOS 2.0 and later.
Declared In
UIInterface.hInstance Methods
fontWithSize:
Returns a font object that is the same as the receiver but which has the specified size instead.
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© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)