Difference between revisions of "UIFont"

From iPhone Development Wiki
Jump to: navigation, search
(Created page with '{{occlass|library=UIKit.framework}} UIFont is a class representing a font face and the font size. This class is built on top of GSFont. == Default font families == {| c…')
 
Line 106: Line 106:
 
| style="font-family: Thonburi;" | Thai-ภาษาไทย
 
| style="font-family: Thonburi;" | Thai-ภาษาไทย
 
|}
 
|}
 +
 +
== Default font sizes ==
 +
There are 4 font sizes that can be obtained using <tt>+[UIFont </tt>''someSize''<tt>]</tt>. The last 2 are conventional values.
 +
{| class="wikitable"
 +
|-
 +
! Name
 +
! Value
 +
|-
 +
| <tt>smallSystemFontSize</tt>
 +
| 12
 +
|-
 +
| <tt>systemFontSize</tt>
 +
| 14
 +
|-
 +
| <tt>labelFontSize</tt>
 +
| 17
 +
|-
 +
| <tt>buttonFontSize</tt>
 +
| 18
 +
|-
 +
| Default font size of [[UIButton]]
 +
| 15
 +
|-
 +
| Default font size of [[UITextField]]
 +
| 12
 +
|}
 +
 +
== Undocumented methods ==
 +
=== +fontWithFamilyName:traits:size: ===
 +
{{Function signature
 +
|signature=+(UIFont*)fontWithFamilyName:(NSString*)familyName traits:(GSFontTraitMask)traits size:(CGFloat)fontSize;
 +
|firmware=2.0 – 3.1
 +
}}
 +
Returns a font with specific family name, traits (bold/italic) and font size. For example:
 +
<source lang="objc">
 +
// Equivalent to [UIFont fontWithName:@"Arial-BoldMT" size:24]
 +
UIFont* font = [UIFont fontWithFamilyName:@"Arial" traits:GSBoldFontMask size:24];
 +
</source>
 +
 +
=== +fontWithMarkupDescription: ===
 +
{{Function signature
 +
|signature=+(UIFont*)fontWithMarkupDescription:(NSString*)markupDescription;
 +
|firmware=2.0 — 3.1
 +
}}
 +
Create a font using a CSS font description, e.g.
 +
<source lang="objc">
 +
// Equivalent to [UIFont fontWithName:@"Arial-BoldMT" size:24]
 +
UIFont* font = [UIFont fontWithMarkupDescription:@"font-family: Arial; font-size: 24px; font-weight: bold;"];
 +
</source>
 +
 +
Unlike real CSS rules there are heavy restrictions on the "markup description":
 +
* The '''font-family''' rule must be exact. A list of fonts like <tt>Arial, Helvetica, sans-serif</tt> will not be supported by UIKit, and will always return <tt>nil</tt> regardless whether any font in the list is available.
 +
* The unit of '''font-size''' will always be interpreted as <tt>px</tt>. Names such as <tt>font-size: large</tt> will be considered as 0px.
 +
* '''font-weight''' can only be <tt>bold</tt> or not.
 +
* '''font-style''' can only be <tt>italic</tt> or not. In particular, <tt>oblique</tt> is not recognized and treated as <tt>normal</tt>.
 +
 +
=== -traits ===
 +
{{Function signature
 +
|signature=-(GSFontTraitMask)traits;
 +
|firmware=2.0 – 3.1
 +
}}
 +
Returns the traits (bold/italic) of the font.
 +
 +
=== -isFixedPitch ===
 +
{{Function signature
 +
|signature=-(BOOL)isFixedPitch;
 +
|firmware=2.0 – 3.1
 +
}}
 +
Returns whether the font is monospaced or not.
 +
 +
=== -markupDescription ===
 +
{{Function signature
 +
|signature=-(NSString*)markupDescription;
 +
|firmware=2.0 – 3.1
 +
}}
 +
Returns the CSS rules that can reproduce this font.
  
 
== References ==
 
== References ==
 
* Official documentation: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIFont_Class/Reference/Reference.html
 
* Official documentation: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIFont_Class/Reference/Reference.html
 
* Extra header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIFont2.h
 
* Extra header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIFont2.h

Revision as of 18:32, 11 October 2009


UIFont is a class representing a font face and the font size. This class is built on top of GSFont.

Default font families

Family Normal Bold Italic Bold-Italic Example
AppleGothic AppleGothic Korean-한국어-韓國語
Hiragino Kaku Gothic ProN HiraKakuProN-W3 HiraKakuProN-W6 Japanese-にほんご-ニヒンゴ-日本語
Arial Unicode MS ArialUnicodeMS Unicode-AMZamz157½ßĽΔΩθφДЫжю
Heiti K STHeitiK-Light STHeitiK-Medium Korean-한국어-韓國語
DB LCD Temp DBLCDTempBlack 0123456789abcdef
Helvetica Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique Latin-AMZamz157½ßĽΔΩθφДЫжю
Marker Felt MarkerFelt-Thin Latin-AMZamz157½ßĽΔΩθφДЫжю
Times New Roman TimesNewRomanPSMT TimesNewRomanPS-BoldMT TimesNewRomanPS-ItalicMT TimesNewRomanPS-BoldItalicMT Latin-AMZamz157½ßĽΔΩθφДЫжю
Verdana Verdana Verdana-Bold Verdana-Italic Verdana-BoldItalic Latin-AMZamz157½ßĽΔΩθφДЫжю
Georgia Georgia Georgia-Bold Georgia-Italic Georgia-BoldItalic Latin-AMZamz157½ßĽΔΩθφДЫжю
Arial Rounded MT Bold ArialRoundedMTBold Latin-AMZamz157½ßĽΔΩθφДЫжю
Trebuchet MS TrebuchetMS TrebuchetMS-Bold TrebuchetMS-Italic Trebuchet-BoldItalic Latin-AMZamz157½ßĽΔΩθφДЫжю
Heiti TC STHeitiTC-Light STHeitiTC-Medium Traditional Chinese-繁體中文
Geeza Pro GeezaPro GeezaPro-Bold Arabic-العربية/Farsi-فارسی
Courier Courier Courier-Bold Courier-Oblique Courier-BoldOblique Latin-AMZamz157½ßĽΔΩθφДЫжю
Arial ArialMT Arial-BoldMT Arial-ItalicMT Arial-BoldItalicMT Latin-AMZamz157½ßĽΔΩθφДЫжю
Heiti J STHeitiJ-Light STHeitiJ-Medium Japanese-にほんご-ニヒンゴ-日本語
Arial Hebrew ArialHebrew ArialHebrew-Bold Hebrew-עִבְרִית
Courier New CourierNewPSMT CourierNewPS-BoldMT CourierNewPS-ItalicMT CourierNewPS-BoldItalicMT Latin-AMZamz157½ßĽΔΩθφДЫжю
Zapfino Zapfino Latin-AMZamz157½ßĽΔΩθφДЫжю
American Typewriter AmericanTypewriter AmericanTypewriter-Bold Latin-AMZamz157½ßĽΔΩθφДЫжю
Heiti SC STHeitiSC-Light STHeitiSC-Medium Simplified Chinese-简体中文
Helvetica Neue HelveticaNeue HelveticaNeue-Bold Latin-AMZamz157½ßĽΔΩθφДЫжю
Thonburi Thonburi Thonburi-Bold Thai-ภาษาไทย

Default font sizes

There are 4 font sizes that can be obtained using +[UIFont someSize]. The last 2 are conventional values.

Name Value
smallSystemFontSize 12
systemFontSize 14
labelFontSize 17
buttonFontSize 18
Default font size of UIButton 15
Default font size of UITextField 12

Undocumented methods

+fontWithFamilyName:traits:size:

Signature +(UIFont*)fontWithFamilyName:(NSString*)familyName traits:(GSFontTraitMask)traits size:(CGFloat)fontSize;
Available in 2.0 – 3.1

Returns a font with specific family name, traits (bold/italic) and font size. For example:

// Equivalent to [UIFont fontWithName:@"Arial-BoldMT" size:24]
UIFont* font = [UIFont fontWithFamilyName:@"Arial" traits:GSBoldFontMask size:24];

+fontWithMarkupDescription:

Signature +(UIFont*)fontWithMarkupDescription:(NSString*)markupDescription;
Available in 2.0 — 3.1

Create a font using a CSS font description, e.g.

// Equivalent to [UIFont fontWithName:@"Arial-BoldMT" size:24]
UIFont* font = [UIFont fontWithMarkupDescription:@"font-family: Arial; font-size: 24px; font-weight: bold;"];

Unlike real CSS rules there are heavy restrictions on the "markup description":

  • The font-family rule must be exact. A list of fonts like Arial, Helvetica, sans-serif will not be supported by UIKit, and will always return nil regardless whether any font in the list is available.
  • The unit of font-size will always be interpreted as px. Names such as font-size: large will be considered as 0px.
  • font-weight can only be bold or not.
  • font-style can only be italic or not. In particular, oblique is not recognized and treated as normal.

-traits

Signature -(GSFontTraitMask)traits;
Available in 2.0 – 3.1

Returns the traits (bold/italic) of the font.

-isFixedPitch

Signature -(BOOL)isFixedPitch;
Available in 2.0 – 3.1

Returns whether the font is monospaced or not.

-markupDescription

Signature -(NSString*)markupDescription;
Available in 2.0 – 3.1

Returns the CSS rules that can reproduce this font.

References