| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Declared in | UIColor.h UIInterface.h |
| Related sample code |
A UIColor object represents color and sometimes opacity (alpha value). You can use UIColor objects to store color data, and during drawing you can use them to set the current fill and stroke colors.
Many methods in UIKit require you to specify color data using a UIColor object, and for general color needs it should be your main way of specifying colors. The color spaces used by this object are optimized for use on iPhone OS–based devices and are therefore appropriate for most drawing needs. If you prefer to use Core Graphics colors and color spaces instead, however, you may do so.
Most developers should have no need to subclass UIColor. The only time doing so might be necessary is if you require support for additional colorspaces or color models.
+ colorWithWhite:alpha:
+ colorWithHue:saturation:brightness:alpha:
+ colorWithRed:green:blue:alpha:
+ colorWithCGColor:
+ colorWithPatternImage:
– colorWithAlphaComponent:
– initWithWhite:alpha:
– initWithHue:saturation:brightness:alpha:
– initWithRed:green:blue:alpha:
– initWithCGColor:
– initWithPatternImage:
+ blackColor
+ darkGrayColor
+ lightGrayColor
+ whiteColor
+ grayColor
+ redColor
+ greenColor
+ blueColor
+ cyanColor
+ yellowColor
+ magentaColor
+ orangeColor
+ purpleColor
+ brownColor
+ clearColor
CGColor property
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
The Quartz color reference that corresponds to the receiver’s color. (read-only)
@property(nonatomic,readonly) CGColorRef CGColor
UIColor.hReturns a color object whose grayscale value is 0.0 and whose alpha value is 1.0.
+ (UIColor *)blackColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 0.0, 0.0, and 1.0 and whose alpha value is 1.0.
+ (UIColor *)blueColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 0.6, 0.4, and 0.2 and whose alpha value is 1.0.
+ (UIColor *)brownColor
The UIColor object.
UIColor.hReturns a color object whose grayscale and alpha values are both 0.0.
+ (UIColor *)clearColor
The UIColor object.
UIColor.hCreates and returns a color object using the specified Quartz color reference.
+ (UIColor *)colorWithCGColor:(CGColorRef)cgColor
A reference to a Quartz color.
The color object. The color information represented by this object is in the native colorspace of the specified Quartz color.
UIColor.hCreates and returns a color object using the specified opacity and HSB color space component values.
+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha
The hue component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.
The saturation component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.
The brightness (or value) component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.
The opacity value of the color object, specified as a value from 0.0 to 1.0.
The color object. The color information represented by this object is in the device RGB colorspace.
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
UIColor.hCreates and returns a color object using the specified image.
+ (UIColor *)colorWithPatternImage:(UIImage *)image
The image to use when creating the pattern color.
The pattern color.
You can use pattern colors to set the fill or stroke color just as you would a solid color. During drawing, the image in the pattern color is tiled as necessary to cover the given area.
By default, the phase of the returned color is 0, which causes the top-left corner of the image to be aligned with the drawing origin. To change the phase, make the color the current color and then use the CGContextSetPatternPhase function to change the phase.
UIColor.hCreates and returns a color object using the specified opacity and RGB component values.
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
The red component of the color object, specified as a value from 0.0 to 1.0.
The green component of the color object, specified as a value from 0.0 to 1.0.
The blue component of the color object, specified as a value from 0.0 to 1.0.
The opacity value of the color object, specified as a value from 0.0 to 1.0.
The color object. The color information represented by this object is in the device RGB colorspace.
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
UIColor.hCreates and returns a color object using the specified opacity and grayscale values.
+ (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha
The grayscale value of the color object, specified as a value from 0.0 to 1.0.
The opacity value of the color object, specified as a value from 0.0 to 1.0.
The color object. The color information represented by this object is in the device gray colorspace.
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
UIColor.hReturns a color object whose RGB values are 0.0, 1.0, and 1.0 and whose alpha value is 1.0.
+ (UIColor *)cyanColor
The UIColor object.
UIColor.hReturns a color object whose grayscale value is 1/3 and whose alpha value is 1.0.
+ (UIColor *)darkGrayColor
The UIColor object.
UIColor.hReturns the system color used for displaying text on a light background.
+ (UIColor *)darkTextColor
The UIColor object.
UIInterface.hReturns a color object whose grayscale value is 0.5 and whose alpha value is 1.0.
+ (UIColor *)grayColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 0.0, 1.0, and 0.0 and whose alpha value is 1.0.
+ (UIColor *)greenColor
The UIColor object.
UIColor.hReturns the system color used for the background of a grouped table.
+ (UIColor *)groupTableViewBackgroundColor
The UIColor object.
UIInterface.hReturns a color object whose grayscale value is 2/3 and whose alpha value is 1.0.
+ (UIColor *)lightGrayColor
The UIColor object.
UIColor.hReturns the system color used for displaying text on a dark background.
+ (UIColor *)lightTextColor
The UIColor object.
UIInterface.hReturns a color object whose RGB values are 1.0, 0.0, and 1.0 and whose alpha value is 1.0.
+ (UIColor *)magentaColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 1.0, 0.5, and 0.0 and whose alpha value is 1.0.
+ (UIColor *)orangeColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 0.5, 0.0, and 0.5 and whose alpha value is 1.0.
+ (UIColor *)purpleColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 1.0, 0.0, and 0.0 and whose alpha value is 1.0.
+ (UIColor *)redColor
The UIColor object.
UIColor.hReturns the system color used for the back side of a view while it is being flipped.
+ (UIColor *)viewFlipsideBackgroundColor
The UIColor object.
UIInterface.hReturns a color object whose grayscale value is 1.0 and whose alpha value is 1.0.
+ (UIColor *)whiteColor
The UIColor object.
UIColor.hReturns a color object whose RGB values are 1.0, 1.0, and 0.0 and whose alpha value is 1.0.
+ (UIColor *)yellowColor
The UIColor object.
UIColor.hCreates and returns a color object that has the same color space and component values as the receiver, but has the specified alpha component.
- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha
The opacity value of the new UIColor object.
The new UIColor object.
A subclass with explicit opacity components should override this method to return a color with the specified alpha.
UIColor.hInitializes and returns a color object using the specified Quartz color reference.
- (UIColor *)initWithCGColor:(CGColorRef)cgColor
A reference to a Quartz color.
An initialized color object. The color information represented by this object is in the native colorspace of the specified Quartz color.
UIColor.hInitializes and returns a color object using the specified opacity and HSB color space component values.
- (UIColor *)initWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha
The hue component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.
The saturation component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.
The brightness (or value) component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.
The opacity value of the color object, specified as a value from 0.0 to 1.0.
An initialized color object. The color information represented by this object is in the device RGB colorspace.
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
UIColor.hInitializes and returns a color object using the specified Quartz color reference.
- (UIColor *)initWithPatternImage:(UIImage *)image
The image to use when creating the pattern color.
The pattern color.
You can use pattern colors to set the fill or stroke color just as you would a solid color. During drawing, the image in the pattern color is tiled as necessary to cover the given area.
By default, the phase of the returned color is 0, which causes the top-left corner of the image to be aligned with the drawing origin. To change the phase, make the color the current color and then use the CGContextSetPatternPhase function to change the phase.
UIColor.hInitializes and returns a color object using the specified opacity and RGB component values.
- (UIColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
The red component of the color object, specified as a value from 0.0 to 1.0.
The green component of the color object, specified as a value from 0.0 to 1.0.
The blue component of the color object, specified as a value from 0.0 to 1.0.
The opacity value of the color object, specified as a value from 0.0 to 1.0.
An initialized color object. The color information represented by this object is in the device RGB colorspace.
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
UIColor.hInitializes and returns a color object using the specified opacity and grayscale values.
- (UIColor *)initWithWhite:(CGFloat)white alpha:(CGFloat)alpha
The grayscale value of the color object, specified as a value from 0.0 to 1.0.
The opacity value of the color object, specified as a value from 0.0 to 1.0.
An initialized color object. The color information represented by this object is in the device gray colorspace.
Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
UIColor.hSets the color of subsequent stroke and fill operations to the color that the receiver represents.
- (void)set
If you subclass UIColor, you must implement this method in your subclass. Your custom implementation should modify both the stroke and fill color in the current graphics context by setting them both to the color represented by the receiver.
UIColor.hSets the color of subsequent fill operations to the color that the receiver represents.
- (void)setFill
If you subclass UIColor, you must implement this method in your subclass. Your custom implementation should modify the fill color in the current graphics context by setting it to the color represented by the receiver.
UIColor.hSets the color of subsequent stroke operations to the color that the receiver represents.
- (void)setStroke
If you subclass UIColor, you must implement this method in your subclass. Your custom implementation should modify the stroke color in the current graphics context by setting it to the color represented by the receiver.
UIColor.hLast updated: 2008-05-27