Class: UIColor

Inherits:
NSObject show all

Overview

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.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (CGColorRef) CGColor (readonly)

The Quartz color reference that corresponds to the receiver’s color. (read-only)

Returns:

  • (CGColorRef)

- (CIColor) CIColor (readonly)

The Core Image color associated with the receiver. (read-only) This property throws an exception if the color object was not initialized with a Core Image color.

Returns:

Class Method Details

+ (UIColor) blackColor

Returns a color object whose grayscale value is 0.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) blueColor

Returns a color object whose RGB values are 0.0, 0.0, and 1.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) brownColor

Returns a color object whose RGB values are 0.6, 0.4, and 0.2 and whose alpha value is 1.0.

Returns:

+ (UIColor) clearColor

Returns a color object whose grayscale and alpha values are both 0.0.

Returns:

+ (UIColor) colorWithCGColor(cgColor)

Creates and returns a color object using the specified Quartz color reference.

Parameters:

  • cgColor (CGColorRef)

    A reference to a Quartz color.

Returns:

  • (UIColor)

    The color object. The color information represented by this object is in the native colorspace of the specified Quartz color.

+ (UIColor) colorWithCIColor(ciColor)

Converts a Core Image color object to its UIColor equivalent

Parameters:

  • ciColor (CIColor)

    The Core Image color to convert.

Returns:

  • (UIColor)

    The UIColor object corresponding to the specified Core Image color.

+ (UIColor) colorWithHue(hue, saturation:saturation, brightness:brightness, alpha:alpha)

Creates and returns a color object using the specified opacity and HSB color space component values. Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

Parameters:

  • hue (Float)

    The hue component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.

  • saturation (Float)

    The saturation component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.

  • brightness (Float)

    The brightness (or value) component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.

  • alpha (Float)

    The opacity value of the color object, specified as a value from 0.0 to 1.0.

Returns:

  • (UIColor)

    The color object. The color information represented by this object is in the device RGB colorspace.

+ (UIColor) colorWithPatternImage(image)

Creates and returns a color object using the specified image. 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.

Parameters:

  • image (UIImage)

    The image to use when creating the pattern color.

Returns:

+ (UIColor) colorWithRed(red, green:green, blue:blue, alpha:alpha)

Creates and returns a color object using the specified opacity and RGB component values. Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

Parameters:

  • red (Float)

    The red component of the color object, specified as a value from 0.0 to 1.0.

  • green (Float)

    The green component of the color object, specified as a value from 0.0 to 1.0.

  • blue (Float)

    The blue component of the color object, specified as a value from 0.0 to 1.0.

  • alpha (Float)

    The opacity value of the color object, specified as a value from 0.0 to 1.0.

Returns:

  • (UIColor)

    The color object. The color information represented by this object is in the device RGB colorspace.

+ (UIColor) colorWithWhite(white, alpha:alpha)

Creates and returns a color object using the specified opacity and grayscale values. Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

Parameters:

  • white (Float)

    The grayscale value of the color object, specified as a value from 0.0 to 1.0.

  • alpha (Float)

    The opacity value of the color object, specified as a value from 0.0 to 1.0.

Returns:

  • (UIColor)

    The color object. The color information represented by this object is in the device gray colorspace.

+ (UIColor) cyanColor

Returns a color object whose RGB values are 0.0, 1.0, and 1.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) darkGrayColor

Returns a color object whose grayscale value is 1/3 and whose alpha value is 1.0.

Returns:

+ (UIColor) darkTextColor

Returns the system color used for displaying text on a light background.

Returns:

+ (UIColor) grayColor

Returns a color object whose grayscale value is 0.5 and whose alpha value is 1.0.

Returns:

+ (UIColor) greenColor

Returns a color object whose RGB values are 0.0, 1.0, and 0.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) groupTableViewBackgroundColor

Returns the system color used for the background of a grouped table.

Returns:

+ (UIColor) lightGrayColor

Returns a color object whose grayscale value is 2/3 and whose alpha value is 1.0.

Returns:

+ (UIColor) lightTextColor

Returns the system color used for displaying text on a dark background.

Returns:

+ (UIColor) magentaColor

Returns a color object whose RGB values are 1.0, 0.0, and 1.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) orangeColor

Returns a color object whose RGB values are 1.0, 0.5, and 0.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) purpleColor

Returns a color object whose RGB values are 0.5, 0.0, and 0.5 and whose alpha value is 1.0.

Returns:

+ (UIColor) redColor

Returns a color object whose RGB values are 1.0, 0.0, and 0.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) scrollViewTexturedBackgroundColor

Returns the system pattern color used to render the area behind scrollable content.

Returns:

+ (UIColor) underPageBackgroundColor

Returns the system pattern color used to render the background of a page.

Returns:

+ (UIColor) viewFlipsideBackgroundColor

Returns the system color used for the back side of a view while it is being flipped.

Returns:

+ (UIColor) whiteColor

Returns a color object whose grayscale value is 1.0 and whose alpha value is 1.0.

Returns:

+ (UIColor) yellowColor

Returns a color object whose RGB values are 1.0, 1.0, and 0.0 and whose alpha value is 1.0.

Returns:

Instance Method Details

- (UIColor) colorWithAlphaComponent(alpha)

Creates and returns a color object that has the same color space and component values as the receiver, but has the specified alpha component. A subclass with explicit opacity components should override this method to return a color with the specified alpha.

Parameters:

  • alpha (Float)

    The opacity value of the new UIColor object.

Returns:

- (Boolean) getHue(hue, saturation:saturation, brightness:brightness, alpha:alpha)

Returns the components that make up the color in the HSB color space. If the color is in a compatible color space, the color is converted into the HSB color space and its components are returned to your application. If the color is not in a compatible color space, the parameters are unchanged.

Parameters:

  • hue (Float)

    On return, the hue component of the color object, specified as a value between 0.0 and 1.0.

  • saturation (Float)

    On return, the saturation component of the color object, specified as a value between 0.0 and 1.0.

  • brightness (Float)

    On return, the brightness component of the color object, specified as a value between 0.0 and 1.0.

  • alpha (Float)

    On return, the opacity component of the color object, specified as a value between 0.0 and 1.0.

Returns:

  • (Boolean)

    YES if the color could be converted, NO otherwise.

- (Boolean) getRed(red, green:green, blue:blue, alpha:alpha)

Returns the components that make up the color in the RGB color space. If the color is in a compatible color space, the color is converted into RGB format and its components are returned to your application. If the color is not in a compatible color space, the parameters are unchanged.

Parameters:

  • red (Float)

    On return, the red component of the color object, specified as a value between 0.0 and 1.0.

  • green (Float)

    On return, the green component of the color object, specified as a value between 0.0 and 1.0.

  • blue (Float)

    On return, the blue component of the color object, specified as a value between 0.0 and 1.0.

  • alpha (Float)

    On return, the opacity component of the color object, specified as a value between 0.0 and 1.0.

Returns:

  • (Boolean)

    YES if the color could be converted, NO otherwise.

- (Boolean) getWhite(white, alpha:alpha)

Returns the grayscale components of the color. If the color is in a compatible color space, the color is converted into grayscale format and returned to your application. If the color is not in a compatible color space, the parameters are unchanged.

Parameters:

  • white (Float)

    On return, the grayscale component of the color object, specified as a value between 0.0 and 1.0.

  • alpha (Float)

    On return, the opacity component of the color object, specified as a value between 0.0 and 1.0.

Returns:

  • (Boolean)

    YES if the color could be converted, NO otherwise.

- (UIColor) initWithCGColor(cgColor)

Initializes and returns a color object using the specified Quartz color reference.

Parameters:

  • cgColor (CGColorRef)

    A reference to a Quartz color.

Returns:

  • (UIColor)

    An initialized color object. The color information represented by this object is in the native colorspace of the specified Quartz color.

- (UIColor) initWithCIColor(ciColor)

Initializes and returns a color object using the specified Core Image color.

Parameters:

  • ciColor (CIColor)

    The Core Image color to convert.

Returns:

  • (UIColor)

    An initialized color object.

- (UIColor) initWithHue(hue, saturation:saturation, brightness:brightness, alpha:alpha)

Initializes and returns a color object using the specified opacity and HSB color space component values. Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

Parameters:

  • hue (Float)

    The hue component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.

  • saturation (Float)

    The saturation component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.

  • brightness (Float)

    The brightness (or value) component of the color object in the HSB color space, specified as a value from 0.0 to 1.0.

  • alpha (Float)

    The opacity value of the color object, specified as a value from 0.0 to 1.0.

Returns:

  • (UIColor)

    An initialized color object. The color information represented by this object is in the device RGB colorspace.

- (UIColor) initWithPatternImage(image)

Initializes and returns a color object using the specified Quartz color reference. 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.

Parameters:

  • image (UIImage)

    The image to use when creating the pattern color.

Returns:

- (UIColor) initWithRed(red, green:green, blue:blue, alpha:alpha)

Initializes and returns a color object using the specified opacity and RGB component values. Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

Parameters:

  • red (Float)

    The red component of the color object, specified as a value from 0.0 to 1.0.

  • green (Float)

    The green component of the color object, specified as a value from 0.0 to 1.0.

  • blue (Float)

    The blue component of the color object, specified as a value from 0.0 to 1.0.

  • alpha (Float)

    The opacity value of the color object, specified as a value from 0.0 to 1.0.

Returns:

  • (UIColor)

    An initialized color object. The color information represented by this object is in the device RGB colorspace.

- (UIColor) initWithWhite(white, alpha:alpha)

Initializes and returns a color object using the specified opacity and grayscale values. Values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.

Parameters:

  • white (Float)

    The grayscale value of the color object, specified as a value from 0.0 to 1.0.

  • alpha (Float)

    The opacity value of the color object, specified as a value from 0.0 to 1.0.

Returns:

  • (UIColor)

    An initialized color object. The color information represented by this object is in the device gray colorspace.

- (Object) set

Sets the color of subsequent stroke and fill operations to the color that the receiver represents. 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.

Returns:

- (Object) setFill

Sets the color of subsequent fill operations to the color that the receiver represents. 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.

Returns:

- (Object) setStroke

Sets the color of subsequent stroke operations to the color that the receiver represents. 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.

Returns: