AppleColor - UBogun/Xojo-iosLib GitHub Wiki
Inherits from AppleObject
Memory leak check: passed
Status: complete
This is an implementation of UIColor, the iOS native color class. Here you find many methods to convert one color type into another and to create background colors filled with a tiled image.
General information
Unlike iOSColor that is treated as a data type, containing mainly its color component values and an alpha value, AppleColor is a class built on AppleObject. In general, you can use it like iOSColor and in case make use of its many conversion features.
Like usual for iOS, the color values are Doubles ranging from 0.0 to 1.0.
iOSColor is an immutable object. If you want to change its values, you have to define another color.
Please note that the conversions to different color modes (HSB, RGBA …) depend on the convertibility of the color into the desired color mode, and the properties (BlueValue, Brightness …) depend on that too. If a color is not convertible, the properties will be 0. You should check the ConvertibleTo properties befoe you take the values for granted.
Constructors
Constructor (aColor As AppleCGColor): Creates a new AppleColor from a CGColor.
Constructor (aColor As AppleCIColor): Creates a new AppleColor from a CIColor.
Constructor (AColor As Color): Returns an AppleColor with the values of a Xojo color.
Constructor (anImage As AppleImage / iOSImage): Creates a "color" with the image tiled as background pattern.
A Color created from an image tiles the image.
Example Code:
dim logo as new AppleImage(iosLibLogo)
dim smallogo as AppleImage= logo.Resize(0.02)
dim c as new applecolor (smallogo)
me.view.BackgroundColor= c
In this case you have to use the view As AppleView property of the canvas and the AppleColor; you cannot use the converted Xojo color and the module methods because a tiled image color cannot be converted to a Xojo color.
Constructor (Red As Double, Green As Double, Blue As Double, Alpha As Double): Creates a new color with the defined values (ranging from 0 to 1).
Constructor (White As Double, Alpha As Double): Creates a grayscale color with the specified white and alpha values.
Properties (all read-only)
AlphaValue, RedValue, GreenValue, BlueValue As Double (read-only): Returns the values of the alpha channel and the Red, Green and Blue values if applicable.
Hue, Saturation, Brightness As Double (read-only): If ConvertibleToHSB is True, you find here the HSB values of the color.
WhiteValue As Double: If ConvertibleToGrayScale is true, returns the white value of the color.
CGColor As AppleCGColor (read-only): A CGColor representation of the color.
ConvertibleToGrayScale As Boolean: Returns True if the color can be converted to a grayscale color.
ConvertibleToHSB As Boolean: Returns True if the color can be converted to HSBA.
ConvertibleToRGB As Boolean: Returns True if the color can be converted (or is defined in) RGB values.
toColor As Color (read-only): Returns a Xojo Color if the color is convertible to RGB(A).
Methods
ChangeAlpha (alpha as double) As AppleColor: Returns a copy of the color with a new alpha value.
CIColor() As AppleCIColor: Returns the CIColor if the color was initialized with a CIColor. Else raises an exception.
SetFill(): Sets the color of subsequent fill operations to the color that the receiver represents. Useful in a context draw operation.
SetStroke(): Sets the color of subsequent stroke operations to the color that the receiver represents. Useful in a context draw operation.
SetStrokeAndFill(): Sets the color of subsequent stroke and fill operations to the color that the receiver represents. Useful in a context draw operation.
Shared Methods
FromColor (aColor As AppleCGColor) As AppleColor: A convenience class method implementation for the Acolor As CGColor constructor to emulate Xojo new Framework behavior.
FromColor (aColor As AppleCIColor) As AppleColor: A convenience class method implementation for the Acolor As CIColor constructor to emulate Xojo new Framework behavior.
FromColor (aColor As Color) As AppleColor: A convenience class method implementation for the Acolor As Color constructor to emulate Xojo new Framework behavior.
FromGrayscale (White As Double, Alpha As Double): Creates a new grayscale color.
FromHSBA (Hue As Double, Saturation As Double, Brightness as Double, Alpha As Double) As AppleColor: Creates a new AppleColor from HSBA values.
Shared Properties
BlackColor, BlueColor, BrownColor, ClearColor, CyanColor, DarkGrayColor, DarkTextColor, GrayColor, GreenColor, GroupTableViewBackgroundColor, LightGrayColor, LightTextColor, MagentaColor, OrangeColor, PurpleColor, RedColor, WhiteColor, YellowColor As AppleColor: Pre-defined system colors for easy access.
Shared methods
FromCGColor (AColor As AppleCGColor) As AppleColor: Conversion, same as new AppleColor(CGColor).
FromCIColor (AColor As AppleCIColor) As AppleColor: Conversion, same as new AppleColor(CGColor).
FromColor (AColor As Color) As AppleColor: Conversion, same as new AppleColor(Color).
FromGrayscale (White As Double, Alpha As Double) As AppleColor: Same as new AppleColor(white, Alpha).
FromHSBA (Hue As Double, Saturation As Double, Brightness as Double, Alpha As Double) as AppleColor: Creates a new Applecolor from HSBA values.