class UIColor
An object that represents a single color value.
class UIColor
Description
Instances of UIColor can be used with style classes and overrides, as well as properties of various UI components, such as UICell.background. The toString() method simply evaluates a CSS-compatible color string as needed, requiring no further logic where colors are used.
UIColor instances can be created with a base color such as #000
or rgba(0, 0, 0, 0.5)
, or a color defined by the current theme (see UITheme). Afterwards, UIColor methods can be used to create derived colors — changing brightness, transparency, or mixing colors together.
A set of base colors corresponding to the default theme colors are available as static properties of ui.color()
. Use these as a starting point wherever possible.
Example
// Different ways to create UIColor objects
new UIColor("#000")
new UIColor("#aabbcc")
new UIColor("rgb(0,0,0)")
new UIColor("rgb(0,0,0,0.5)")
new UIColor("Black") // theme color name
ui.color.BLACK // same as above, recommended
ui.color.GREEN.alpha(0.5)
ui.color.PRIMARY_BG.text()
ui.color.PRIMARY_BG.brighten(0.2).text()
Constructor
- constructor(color?)Creates a new UIColor instance.
Static Members
- UIColor.isBrightColor(color) staticReturns true if the pseudo-brightness of the specified color is greater than 55%.
- UIColor.mixColors(color1, color2, ratio, ignoreAlpha?) staticReturns the result of mixing two colors together at the specified ratio.
Instance Members
- alpha(alpha)Returns a new UIColor instance with increased transparency.
- brighten(d)Returns a new UIColor instance with increased (or decreased) brightness.
- contrast(d)Returns a new UIColor instance with increased (or decreased) contrast compared to 50% grey.
- fg(colorOnLight, colorOnDark)Returns a new UIColor instance for a suitable foreground color based on the current color.
- text()Returns a new UIColor instance for a suitable text color (black or white).
- mix(color, amount, ignoreAlpha?)Returns a new UIColor instance for a color that’s closer to the specified color.
- toString()Returns a CSS-compatible string representation of the current color.