uikit——UIColor

xiaoxiao2021-02-28  129

create

// Convenience methods for creating colors + (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha; + (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha; + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; + (UIColor *)colorWithCGColor:(CGColorRef)cgColor; + (UIColor *)colorWithPatternImage:(UIImage *)image; #if __has_include(<CoreImage/CoreImage.h>) + (UIColor *)colorWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0); #endif 解释: 支持gray colorspace支持HSB colorspace支持RGB colorspace支持Quartz color支持pattern image,tile模式填充,相位默认为0,即image top-left corner与填充区域原点对齐支持Core Image color

init

// Initializers for creating colors - (UIColor *)initWithWhite:(CGFloat)white alpha:(CGFloat)alpha; - (UIColor *)initWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha; - (UIColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; - (UIColor *)initWithCGColor:(CGColorRef)cgColor; - (UIColor *)initWithPatternImage:(UIImage*)image; #if __has_include(<CoreImage/CoreImage.h>) - (UIColor *)initWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0); #endif 注:各UIColor模式对应init

改变alpha

// Returns a color in the same color space as the receiver with the specified alpha component. - (UIColor *)colorWithAlphaComponent:(CGFloat)alpha; 注:返回receiver相同UIColor,除alpha自定义

预定义颜色

// Some convenience methods to create colors. These colors will be as calibrated as possible. // These colors are cached. + (UIColor *)blackColor; // 0.0 white + (UIColor *)darkGrayColor; // 0.333 white + (UIColor *)lightGrayColor; // 0.667 white + (UIColor *)whiteColor; // 1.0 white + (UIColor *)grayColor; // 0.5 white + (UIColor *)redColor; // 1.0, 0.0, 0.0 RGB + (UIColor *)greenColor; // 0.0, 1.0, 0.0 RGB + (UIColor *)blueColor; // 0.0, 0.0, 1.0 RGB + (UIColor *)cyanColor; // 0.0, 1.0, 1.0 RGB + (UIColor *)yellowColor; // 1.0, 1.0, 0.0 RGB + (UIColor *)magentaColor; // 1.0, 0.0, 1.0 RGB + (UIColor *)orangeColor; // 1.0, 0.5, 0.0 RGB + (UIColor *)purpleColor; // 0.5, 0.0, 0.5 RGB + (UIColor *)brownColor; // 0.6, 0.4, 0.2 RGB + (UIColor *)clearColor; // 0.0 white, 0.0 alpha 注:预定义颜色预先cached,并非调用时创建

系统颜色

// System colors @interface UIColor (UIColorSystemColors) + (UIColor *)lightTextColor __TVOS_PROHIBITED; // for a dark background + (UIColor *)darkTextColor __TVOS_PROHIBITED; // for a light background + (UIColor *)groupTableViewBackgroundColor __TVOS_PROHIBITED; + (UIColor *)viewFlipsideBackgroundColor NS_DEPRECATED_IOS(2_0, 7_0) __TVOS_PROHIBITED; + (UIColor *)scrollViewTexturedBackgroundColor NS_DEPRECATED_IOS(3_2, 7_0) __TVOS_PROHIBITED; + (UIColor *)underPageBackgroundColor NS_DEPRECATED_IOS(5_0, 7_0) __TVOS_PROHIBITED; @end

获取颜色信息

// Access the underlying CGColor or CIColor. @property(nonatomic,readonly) CGColorRef CGColor; - (CGColorRef)CGColor NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED; #if __has_include(<CoreImage/CoreImage.h>) @property(nonatomic,readonly) CIColor *CIColor NS_AVAILABLE_IOS(5_0); #endif // Convenience methods for getting components. // If the receiver is of a compatible color space, any non-NULL parameters are populated and 'YES' is returned. Otherwise, the parameters are left unchanged and 'NO' is returned. - (BOOL)getWhite:(nullable CGFloat *)white alpha:(nullable CGFloat *)alpha NS_AVAILABLE_IOS(5_0); - (BOOL)getHue:(nullable CGFloat *)hue saturation:(nullable CGFloat *)saturation brightness:(nullable CGFloat *)brightness alpha:(nullable CGFloat *)alpha NS_AVAILABLE_IOS(5_0); - (BOOL)getRed:(nullable CGFloat *)red green:(nullable CGFloat *)green blue:(nullable CGFloat *)blue alpha:(nullable CGFloat *)alpha NS_AVAILABLE_IOS(5_0); 解释: 如果receiver并非Core Image Color模式,获取Core Image Color模式属性throw exception获取gray color space,HSB color space, RGB color space属性时,如果receiver兼容,返回YES及对应属性值,如果receiver不兼容,返回NO

Drawing Operation

// Set the color: Sets the fill and stroke colors in the current drawing context. Should be implemented by subclassers. - (void)set; // Set the fill or stroke colors individually. These should be implemented by subclassers. - (void)setFill; - (void)setStroke; 解释: set设置填充和轮廓颜色setFill设置填充颜色setStroke设置轮廓颜色
转载请注明原文地址: https://www.6miu.com/read-34267.html

最新回复(0)