Formatted String
NativeScript has a special class called FormattedString to support various text transformations and decorations. The FormattedString class can be used with all text-related components like Label, TextView, TextField and even Button.
Usage
NativeScript has a special class called FormattedString to support various text transformations and decorations. The FormattedString class can be used with all text-related components like Label, TextView, TextField and even Button.
Label with formatted string
<Label>
<FormattedString>
<Span text="Words " color="#006600">
</Span>
<Span text="with " color="#990000" fontWeight="Bold">
</Span>
<Span text="different " color="#ffcc00">
</Span>
<Span text="color.">
</Span>
</FormattedString>
</Label>
TextField with formatted string
<TextField>
<FormattedString>
<Span text="Formatted " fontSize="16">
</Span>
<Span text="String " fontSize="18">
</Span>
<Span text="TextField" fontSize="22">
</Span>
</FormattedString>
</TextField>
TextView with formatted string
Button with formatted string
Tips And Tricks
Creating Button via Code-Behind
FormattedStrings could also be defined via code-behind.
Label with formatted string
TextField with formatted string
TextView with formatted string
Button with formatted string
Properties
| Name | Type | Description |
|---|---|---|
spans |
ObservableArray<Span> |
An observable collection of Span objects used to define common text properties. |
API References
| Name | Type | API Reference Link |
|---|---|---|
| tns-core-modules/text/formatted-string | Module |
|
| Span | Module |
|
| ViewBase | Class |