UIColor Struct
Provides an enhanced representation of a Color object that supports the RGB, HSB, and HLS color models, conversion between models, and numerous other color helper methods.
public struct UIColor : IEquatable<UIColor>, IEquatable<Color?>
- Implements:
- IEquatable<UIColor> IEquatable<Color?>
Properties
A
The alpha component value of this UIColor structure.
public byte A { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 255.
B
The RGB blue component value of this UIColor structure.
public byte B { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 255.
ExceedsW3CBrightnessThreshold
Indicates whether the color exceeds the W3C threshold for brightness.
public readonly bool ExceedsW3CBrightnessThreshold { get; }
Property Value
- bool:
trueif the color exceeds the W3C threshold for brightness; otherwise,false.
G
The RGB green component value of this UIColor structure.
public byte G { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 255.
HlsHue
The HLS hue component value of this UIColor structure.
public double HlsHue { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 360.
HlsLightness
The HLS lightness component value of this UIColor structure.
public double HlsLightness { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 1.
HlsSaturation
The HLS saturation component value of this UIColor structure.
public double HlsSaturation { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 1.
HsbBrightness
The HSB brightness component value of this UIColor structure.
public double HsbBrightness { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 1.
HsbHue
The HSB hue component value of this UIColor structure.
public double HsbHue { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 360.
HsbSaturation
The HSB saturation component value of this UIColor structure.
public double HsbSaturation { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 1.
IsGrayscale
Indicates whether the color is grayscale.
public readonly bool IsGrayscale { get; }
Property Value
- bool:
trueif the color is grayscale; otherwise,false.
IsLight
Indicates whether the color is a light color.
public readonly bool IsLight { get; }
Property Value
- bool:
trueif the color is a light color; otherwise,false.
Luminance
The luminance of the color.
public readonly byte Luminance { get; }
Property Value
Remarks
Valid values are in the range 0 to 255.
R
The RGB red component value of this UIColor structure.
public byte R { readonly get; set; }
Property Value
Remarks
Valid values are in the range 0 to 255.
W3CBrightness
The brightness of the color, based on the W3C formula for calculating brightness.
Methods
AdaptToBackground(double, double, double, bool)
Converts the color so that it renders clearly on the specified background color.
public void AdaptToBackground(double backColorHue, double backColorLightness, double backColorSaturation, bool isHighContrast)
| Parameter | Type | Description |
|---|---|---|
| backColorHue | double | The background color hue. |
| backColorLightness | double | The background color lightness. |
| backColorSaturation | double | The background color saturation. |
| isHighContrast | bool | Whether in a high-contrast theme. |
AdaptToBackground(Color, bool)
Converts the color so that it renders clearly on the specified background color.
public void AdaptToBackground(Color backColor, bool isHighContrast)
| Parameter | Type | Description |
|---|---|---|
| backColor | Color | The background color. |
| isHighContrast | bool | Whether in a high-contrast theme. |
Darken(double)
Darkens the color by the specified amount.
public void Darken(double percentage)
| Parameter | Type | Description |
|---|---|---|
| percentage | double | The percentage by which to darken the color. The value must be between |
Equals(UIColor)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(UIColor other)
| Parameter | Type | Description |
|---|---|---|
| other | UIColor | An object to compare with this object. |
Returns
- bool:
trueif the current object is equal to theotherparameter; otherwise,false.
Equals(Color?)
Determines whether the specified color is equal to the current color.
public readonly bool Equals(Color? obj)
| Parameter | Type | Description |
|---|---|---|
| obj | Color? | The color to compare to the current color. |
Returns
- bool:
trueif the specified color is equal to the current color; otherwise,false.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object to compare with the current instance. |
Returns
- bool:
trueifobjand this instance are the same type and represent the same value; otherwise,false.
FromAhls(byte, double, double, double)
Creates a UIColor structure from an alpha value and the specified HLS color values (hue, lightness, and saturation).
public static UIColor FromAhls(byte alpha, double hue, double lightness, double saturation)
| Parameter | Type | Description |
|---|---|---|
| alpha | byte | The alpha component value for the new UIColor structure. Valid values are 0 through 255. |
| hue | double | The hue component value for the new UIColor structure. Valid values are 0 through 360. |
| lightness | double | The lightness component value for the new UIColor structure. Valid values are 0 through 1. |
| saturation | double | The saturation component value for the new UIColor structure. Valid values are 0 through 1. |
Returns
Remarks
Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.
FromAhsb(byte, double, double, double)
Creates a UIColor structure from an alpha value and the specified HSB color values (hue, saturation, and brightness).
public static UIColor FromAhsb(byte alpha, double hue, double saturation, double brightness)
| Parameter | Type | Description |
|---|---|---|
| alpha | byte | The alpha component value for the new UIColor structure. Valid values are 0 through 255. |
| hue | double | The hue component value for the new UIColor structure. Valid values are 0 through 360. |
| saturation | double | The saturation component value for the new UIColor structure. Valid values are 0 through 1. |
| brightness | double | The brightness component value for the new UIColor structure. Valid values are 0 through 1. |
Returns
Remarks
Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.
FromArgb(byte, byte, byte, byte)
Creates a UIColor structure from an alpha value and the specified RGB color values (red, green, and blue).
public static UIColor FromArgb(byte alpha, byte red, byte green, byte blue)
| Parameter | Type | Description |
|---|---|---|
| alpha | byte | The alpha component value for the new UIColor structure. Valid values are 0 through 255. |
| red | byte | The red component value for the new UIColor structure. Valid values are 0 through 255. |
| green | byte | The red component value for the new UIColor structure. Valid values are 0 through 255. |
| blue | byte | The red component value for the new UIColor structure. Valid values are 0 through 255. |
Returns
Remarks
Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.
FromColor(Color)
public static UIColor FromColor(Color color)
| Parameter | Type | Description |
|---|---|---|
| color | Color | The Color to use as a template. |
Returns
FromColorComplement(Color)
public static UIColor FromColorComplement(Color color)
| Parameter | Type | Description |
|---|---|---|
| color | Color | The Color to complement and use as a template. |
Returns
FromColorComplement(Color, byte)
public static UIColor FromColorComplement(Color color, byte alpha)
| Parameter | Type | Description |
|---|---|---|
| color | Color | The Color to complement and use as a template. |
| alpha | byte | The alpha channel value to use for the new color. |
Returns
FromHls(double, double, double)
Creates a UIColor structure from the specified HLS color values (hue, lightness, and saturation).
public static UIColor FromHls(double hue, double lightness, double saturation)
| Parameter | Type | Description |
|---|---|---|
| hue | double | The hue component value for the new UIColor structure. Valid values are 0 through 360. |
| lightness | double | The lightness component value for the new UIColor structure. Valid values are 0 through 1. |
| saturation | double | The saturation component value for the new UIColor structure. Valid values are 0 through 1. |
Returns
Remarks
The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.
FromHsb(double, double, double)
Creates a UIColor structure from the specified HSB color values (hue, saturation, and brightness).
public static UIColor FromHsb(double hue, double saturation, double brightness)
| Parameter | Type | Description |
|---|---|---|
| hue | double | The hue component value for the new UIColor structure. Valid values are 0 through 360. |
| saturation | double | The saturation component value for the new UIColor structure. Valid values are 0 through 1. |
| brightness | double | The brightness component value for the new UIColor structure. Valid values are 0 through 1. |
Returns
Remarks
The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to the values indicated above.
FromKnownColor(KnownColor)
Creates a UIColor structure from the specified pre-defined color.
public static UIColor FromKnownColor(KnownColor color)
| Parameter | Type | Description |
|---|---|---|
| color | KnownColor | An element of the KnownColor enumeration. |
Returns
FromMix(Color, Color, double)
Creates a UIColor structure that is the specified percentage between the value of two Color objects.
public static UIColor FromMix(Color color1, Color color2, double percentage)
| Parameter | Type | Description |
|---|---|---|
| color1 | Color | The first Color to examine. |
| color2 | Color | The second Color to examine. |
| percentage | double | The percentage from the first color to the second in which to return a color. |
Returns
FromName(string)
Creates a UIColor structure from the specified name of a pre-defined color.
public static UIColor FromName(string name)
| Parameter | Type | Description |
|---|---|---|
| name | string | A string that is the name of a pre-defined color. Valid names are the same as the names of the elements of the KnownColor enumeration. |
Returns
FromRgb(byte, byte, byte)
Creates a UIColor structure from the specified RGB color values (red, green, and blue).
public static UIColor FromRgb(byte red, byte green, byte blue)
| Parameter | Type | Description |
|---|---|---|
| red | byte | The red component value for the new UIColor structure. Valid values are 0 through 255. |
| green | byte | The red component value for the new UIColor structure. Valid values are 0 through 255. |
| blue | byte | The red component value for the new UIColor structure. Valid values are 0 through 255. |
Returns
Remarks
The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.
FromWebColor(string)
Creates a UIColor structure from the specified web color.
public static UIColor FromWebColor(string text)
| Parameter | Type | Description |
|---|---|---|
| text | string | A string containing the color. |
Returns
Remarks
This method can process HTML color specifications (e.g. #FF00FF) and known color names.
GetContrastRatioWith(UIColor)
Returns the contrast ratio of this color with the specified color.
public readonly double GetContrastRatioWith(UIColor contrastingColor)
| Parameter | Type | Description |
|---|---|---|
| contrastingColor | UIColor | The contrasting color to compare. |
Returns
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int:
A 32-bit signed integer that is the hash code for this instance.
GetStandardCustomColors()
Returns a Color array containing all of the standard custom values.
GetSystemColors()
Returns a Color array containing all of the SystemColors values.
GetTintedColor(Color, Color)
Returns the custom tinted color for the specified base color.
public static Color GetTintedColor(Color baseColor, Color tintColor)
| Parameter | Type | Description |
|---|---|---|
| baseColor | Color | The base Color to examine. |
| tintColor | Color | The tint Color. |
Returns
GetWebColors()
Returns an array containing all of the web color values.
Grayscale()
Converts the color to grayscale.
public void Grayscale()
Lighten(double)
Lightens the color by the specified amount.
public void Lighten(double percentage)
| Parameter | Type | Description |
|---|---|---|
| percentage | double | The percentage by which to lighten the color. The value must be between |
Tint(Color)
Tints this color towards the specified tint Color.
ToColor()
ToKnownColor()
The KnownColor value of this KnownColor structure.
public readonly KnownColor ToKnownColor()
Returns
- KnownColor:
An element of the KnownColor enumeration, if the UIColor structure is created from a pre-defined color by using either the FromName(string) method or the FromKnownColor(KnownColor) method; otherwise, zero.
ToString()
Returns the string representation of this object.
public override readonly string ToString()
Returns
- string:
The string representation of this object.
ToWebColor()
Converts the UIColor to a web color.
public readonly string ToWebColor()
Returns
- string:
The color in HTML color specification format (e.g. #FF00FF).
ToWebColor(bool)
Converts the UIColor to a web color.
public readonly string ToWebColor(bool includeAlpha)
| Parameter | Type | Description |
|---|---|---|
| includeAlpha | bool | Whether to include the alpha specification. |
Returns
- string:
The color in HTML color specification format (e.g. #FFFF00FF).
TryFromName(string, out UIColor)
Tries to create a UIColor structure from the specified name of a pre-defined color.
public static bool TryFromName(string name, out UIColor color)
| Parameter | Type | Description |
|---|---|---|
| name | string | A string that is the name of a pre-defined color. Valid names are the same as the names of the elements of the KnownColor enumeration. |
| color | UIColor | Returns the UIColor structure that this method creates. |
Returns
- bool:
trueif the name was recognized successfully; otherwise,false.
TryFromWebColor(string, out UIColor)
Tries to create a UIColor structure from the specified web color.
public static bool TryFromWebColor(string text, out UIColor color)
| Parameter | Type | Description |
|---|---|---|
| text | string | A string containing the color. |
| color | UIColor | Returns the UIColor structure that this method creates. |
Returns
- bool:
trueif the text was parsed successfully; otherwise,false.
Remarks
This method can process HTML color specifications (e.g. #FF00FF) and known color names.
Operators
operator ==(UIColor, UIColor)
Compares two color objects for equality.
public static bool operator ==(UIColor left, UIColor right)
| Parameter | Type | Description |
|---|---|---|
| left | UIColor | A UIColor to compare. |
| right | UIColor | A UIColor to compare. |
Returns
- bool:
trueif the color values ofleftandrightare equal; otherwise,false.
implicit operator Color(UIColor)
public static implicit operator Color(UIColor color)
| Parameter | Type | Description |
|---|---|---|
| color | UIColor | the UIColor to examine. |
Returns
implicit operator UIColor(Color)
public static implicit operator UIColor(Color color)
| Parameter | Type | Description |
|---|---|---|
| color | Color | the Color to examine. |
Returns
operator !=(UIColor, UIColor)
Compares two color objects for inequality.
public static bool operator !=(UIColor left, UIColor right)
| Parameter | Type | Description |
|---|---|---|
| left | UIColor | A UIColor to compare. |
| right | UIColor | A UIColor to compare. |
Returns
- bool:
trueif the color values ofleftandrightare unequal; otherwise,false.