# Attribute
An abstract datatype for specifying an attributed string attribute.
NOTE
This is an abstract type. Any object of this structure can be used where this type is used.
# Overview
Attributes are added to the Titanium.UI.AttributedString object to create
styled text. The attribute is a JavaScript Object containing three properties:
type
, value
and range
.
# Properties
# range
Attribute range.
This specifies the range of text to apply the property to, as an array of two numbers: [from, length]
.
# type
Attribute to apply to the text.
On Android, only the following constants are supported Titanium.UI.ATTRIBUTE_FONT, Titanium.UI.ATTRIBUTE_FOREGROUND_COLOR, Titanium.UI.ATTRIBUTE_BACKGROUND_COLOR, Titanium.UI.ATTRIBUTE_STRIKETHROUGH_STYLE, Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE, Titanium.UI.ATTRIBUTE_LINK, Titanium.UI.ATTRIBUTE_UNDERLINE_COLOR
ON iOS, Titanium.UI.ATTRIBUTE_LINK only supported on Titanium.UI.TextArea, with editable set to false and autoLink enabled.
- Titanium.UI.ATTRIBUTE_FONT
- Titanium.UI.ATTRIBUTE_FOREGROUND_COLOR
- Titanium.UI.ATTRIBUTE_BACKGROUND_COLOR
- Titanium.UI.ATTRIBUTE_STRIKETHROUGH_STYLE
- Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE
- Titanium.UI.ATTRIBUTE_LINK
- Titanium.UI.ATTRIBUTE_UNDERLINE_COLOR
- Titanium.UI.ATTRIBUTE_LIGATURE
- Titanium.UI.ATTRIBUTE_KERN
- Titanium.UI.ATTRIBUTE_STROKE_COLOR
- Titanium.UI.ATTRIBUTE_STROKE_WIDTH
- Titanium.UI.ATTRIBUTE_SHADOW
- Titanium.UI.ATTRIBUTE_WRITING_DIRECTION
- Titanium.UI.ATTRIBUTE_TEXT_EFFECT
- Titanium.UI.ATTRIBUTE_BASELINE_OFFSET
- Titanium.UI.ATTRIBUTE_STRIKETHROUGH_COLOR
- Titanium.UI.ATTRIBUTE_OBLIQUENESS
- Titanium.UI.ATTRIBUTE_EXPANSION
- Titanium.UI.ATTRIBUTE_LINE_BREAK
# value
Attribute value.
The value
parameter depends on the type
parameter. For example, to
use the foreground color on the text you would use ATTRIBUTE_FOREGROUND_COLOR
for the type
and a color value for the value
:
{
type: Titanium.UI.ATTRIBUTE_FOREGROUND_COLOR,
value: '#DDD',
range: [0, 100]
}
On iOS, if you use ATTRIBUTE_UNDERLINES_STYLE or ATTRIBUTE_STRIKETHROUGH_STYLE, you must use one or more of these constants:
- ATTRIBUTE_UNDERLINE_STYLE_NONE
- ATTRIBUTE_UNDERLINE_STYLE_SINGLE
- ATTRIBUTE_UNDERLINE_STYLE_THICK
- ATTRIBUTE_UNDERLINE_STYLE_DOUBLE
- ATTRIBUTE_UNDERLINE_PATTERN_SOLID
- ATTRIBUTE_UNDERLINE_PATTERN_DOT
- ATTRIBUTE_UNDERLINE_PATTERN_DASH
- ATTRIBUTE_UNDERLINE_PATTERN_DASH_DOT
- ATTRIBUTE_UNDERLINE_PATTERN_DASH_DOT_DOT
- ATTRIBUTE_UNDERLINE_BY_WORD
These can be combined:
{
type: Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE,
value: Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_SINGLE | Titanium.UI.ATTRIBUTE_UNDERLINE_PATTERN_DASH,
range: [0, 100]
}
On iOS, if you use the ATTRIBUTE_WRITING_DIRECTION, you must use one or more of these constants:
- ATTRIBUTE_WRITING_DIRECTION_EMBEDDING
- ATTRIBUTE_WRITING_DIRECTION_OVERRIDE
- ATTRIBUTE_WRITING_DIRECTION_NATURAL
- ATTRIBUTE_WRITING_DIRECTION_LEFT_TO_RIGHT
- ATTRIBUTE_WRITING_DIRECTION_RIGHT_TO_LEFT
These can also be combined the same way as the underline styles.
On iOS, if you use the ATTRIBUTE_SHADOW, the value
must be a JavaScript object containing
any of the offset
, blurRadius
or color
properties:
{
offset: {
width: 10,
height: 10
},
blurRadius: 10,
color: 'red'
}
On IOS, if you use the ATTRIBUTE_PARAGRAPH_STYLE, the value
must be ParagraphAttribute.
E.g:
{
minimumLineHeight: 10.0,
tailIndent: 5,
lineBreakMode: Titanium.UI.ATTRIBUTE_LINE_BREAK_BY_WORD_WRAPPING
}
On iOS, if you use the ATTRIBUTE_TEXT_EFFECT, you must use the ATTRIBUTE_LETTERPRESS_STYLE constant.
On iOS, if you use the ATTRIBUTE_LINE_BREAK, you must use one of these constants:
- ATTRIBUTE_LINE_BREAK_BY_WORD_WRAPPING
- ATTRIBUTE_LINE_BREAK_BY_CHAR_WRAPPING
- ATTRIBUTE_LINE_BREAK_BY_CLIPPING
- ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_HEAD
- ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_TAIL
- ATTRIBUTE_LINE_BREAK_BY_TRUNCATING_MIDDLE
These can also be combined the same way as the underline styles.
- Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_NONE
- Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_SINGLE
- Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_THICK
- Titanium.UI.ATTRIBUTE_UNDERLINE_STYLE_DOUBLE
- Titanium.UI.ATTRIBUTE_WRITING_DIRECTION_EMBEDDING
- Titanium.UI.ATTRIBUTE_WRITING_DIRECTION_OVERRIDE
- Titanium.UI.ATTRIBUTE_WRITING_DIRECTION_NATURAL
- Titanium.UI.ATTRIBUTE_WRITING_DIRECTION_LEFT_TO_RIGHT
- Titanium.UI.ATTRIBUTE_WRITING_DIRECTION_RIGHT_TO_LEFT
- Titanium.UI.ATTRIBUTE_LETTERPRESS_STYLE