Color
The Color class allows you to create custom colors that you can use to style the UI. You can create a color object from different types of input types, as shown below, that stores all color components (alpha (opacity), red, green, blue) in a [0..255] range:
-
Color(knownColor: string)
-
Color(hex: string)
-
Color(argb: number)
-
Color(alpha: number, red: number, green:number, blue: number, type?: 'rgb' \| 'hsl' \| 'hsv')
Properties
Name | Type | Description |
---|---|---|
|
|
Gets the Alpha component (in the [0, 255] range) of the color. This is a read-only property. |
|
|
Gets the Red component (in the [0, 255] range) of the color. This is a read-only property. |
|
|
Gets the Green component (in the [0, 255] range) of the color. This is a read-only property. |
|
|
Gets the Blue component (in the [0, 255] range) of the color. This is a read-only property. |
|
|
Gets the Argb Number representation of this color where each 8 bits represent a single color component. This is a read-only property. |
|
|
Gets the Hexadecimal string representation of the color. This is a read-only property |
|
|
Gets the known name of this instance. Defined only if it has been constructed from a known color name - e.g."red". This is a read-only property. |
|
|
Gets the android-specific integer value representation. Same as the Argb one. This is a read-only property. |
|
|
Gets the iOS-specific UIColor value representation. This is a read-only property. |
Static Methods
Name | Return Type | Description |
---|---|---|
|
|
Compares two |
|
|
Validates if a value can be converted to a color. |
|
|
Creates color from iOS-specific UIColor value representation |
|
|
Mixes |
|
|
Returns a new |
|
|
Returns a new |
Instance Methods
Name | Return Type | Description |
---|---|---|
|
|
Specifies whether the created Color is equal to the Color parameter. |
|
|
Returns true if |
|
|
Returns true if |
|
|
Returns the brightness. |
|
|
Returns the luminance. |
|
|
Return the created color (as a new Color instance) with the provided alpha |
|
|
Return the hsl representation of the color. |
|
|
Returns the CSS hsv representation of the color |
|
|
Returns the hsv representation of the color. |
|
|
Returns the CSS rgb representation of the color |
|
|
Desaturates the color a given amount, from |
|
|
Saturates the color a given amount, from |
|
|
Completely desaturates a color into greyscale.
Same as calling |
|
|
Lightens the color a given amount, from |
|
|
Brightens the color a given amount, from |
|
|
Darkens the color a given amount, from |
|
|
Spins the hue a given amount, from |
|
|
Returns the color complement |
Usage
import { Color } from '@nativescript/core'
function createColor() {
// Using hex values to create color;
const colorHex = new Color('#FF00CC')
const colorShortHex = new Color('#F0C')
// Creates the color with 100 alpha, 255 red, 100 green, 100 blue
const colorARGB = new Color(100, 255, 100, 100)
// Creates the color with 100 alpha, 100 red, 100 green, 100 blue
const argb = (100 << 24) | (100 << 16) | (100 << 8) | 100 //eslint-disable-line no-bitwise
const colorSingleARGB = new Color(argb)
}
import { Color } from '@nativescript/core'
function createColor() {
// Using hex values to create color;
const colorHex = new Color('#FF00CC')
const colorShortHex = new Color('#F0C')
// Creates the color with 100 alpha, 255 red, 100 green, 100 blue
const colorARGB = new Color(100, 255, 100, 100)
// Creates the color with 100 alpha, 100 red, 100 green, 100 blue
const argb = (100 << 24) | (100 << 16) | (100 << 8) | 100
const colorSingleARGB = new Color(argb)
}