Font

An abstract datatype for specifying a text font.

Available fonts vary by platform and device. On iOS, font support depends on the OS version. On Android, font support depends on the OS version and device manufacturer.

Note that to update the font used by a UI component, you must set the object's font property, like this:

myLabel.font = {
    fontSize: 24,
    fontFamily: myFontName
}

Changing the font object after assigning it does not reliably affect the underlying UI component:

// This may not work as expected
myLabel.font.fontSize = 24;

Custom Fonts

Custom TrueType (.ttf) or OpenType (.otf) fonts may be embedded in an application on iOS and Android. (Note that you must have redistribution rights on the fonts you ship.)

In Alloy applications, custom fonts must be placed in a "fonts" folder in the platform-specific assets folder (app/assets/android/fonts, for example). In classic Titanium applications, custom fonts must be placed in the Resources/fonts directory.

For an example of using custom fonts, see Custom Fonts.

  • 0.8
  • 0.8
  • 0.8

NOTE This is an abstract type. Any object meeting this description can be used where this type is used.

Defined By

Properties

Font
: String
Specifies the font family or specific font to use. ...

Specifies the font family or specific font to use.

This can be the name of a font family (for example, "Helvetica" or "DroidSans") the base name of the font file (for example, "Droid_sans.ttf"), or the font's PostScript name. The value you specify also depends on the platform you are targeting.

  • On Android specify the font file name without its file extension (.otf or .ttf). For example, if you were using the "Burnstown Dam" font whose file name is named burnstown_dam.ttf, then you specify fontFamily: 'burnstown_dam'.

  • On iOS you use the font's PostScript name. For example, the PostScript name for Burnstown Dam is "BurnstownDam-Regular so you'd specify: fontFamily: 'BurnstownDam-Regular'.

For an example of using a custom font, see Custom Fonts.

Notes:

  • Available fonts differ by platform.
  • If the requested family name does not match an existing font, the default font family is used.
  • On Android, the generic names "sans-serif," "serif," and "monospace" (or "monospaced") are mapped to system fonts. On iOS, only "monospace" is supported.

Default: Uses the default system font.

Font
: Number/String
Font size, in platform-dependent units. ...

Font size, in platform-dependent units.

On iOS, font sizes are always specified in typographical points (not to be confused with the Apple "points" used for other measurements on iOS).

On Android the default font sizing is in pixels, but the size can also include a unit specifier. Supported units and their specifiers are:

  • pixels (px)
  • typographical points (pt)
  • density-independent pixels (dp or dip)
  • millimeters (mm)
  • inches (in)

For example, "16dp" specifies a size of 16 density-independent pixels.

iOS ignores any unit specifier after the size value.

Default: 15px

Font
: String
Font style. ...

Font style. Valid values are "italic" or "normal".

Default: normal

  • 0.8
  • 0.8
Font
: String
Font weight. ...

Font weight. Valid values are "bold", "semibold", "normal", "thin", "light" and "ultralight".

The "semibold", "thin", "light" and "ultralight" weights are recognized on iOS only. "thin", "light" and "ultralight" are only available on iOS 8.2 and later.

Default: normal

Font
: String
The text style for the font. ...

The text style for the font.

Requires: iOS 7.0 and later

Use one of the TEXT_STYLE constants from Titanium.UI to set the font to a predefined system font. When this property is set to a valid value, all other font properties are ignored. Avaliable on iOS 7 and above.

This API can be assigned the following constants:

  • 3.2.0
  • 3.2.0