UIColor.h

作者: zhYx_ | 来源:发表于2019-06-18 11:45 被阅读0次
    
    #if USE_UIKIT_PUBLIC_HEADERS || !__has_include(<UIKitCore/UIColor.h>)
    //
    //  UIColor.h
    //  UIKit
    //
    //  Copyright (c) 2005-2018 Apple Inc. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import <CoreGraphics/CoreGraphics.h>
    #import <UIKit/UIKitDefines.h>
    #if __has_include(<CoreImage/CoreImage.h>)
    #import <CoreImage/CoreImage.h>
    #endif
    
    
    NS_ASSUME_NONNULL_BEGIN
    
    @class UIImage;
    @class UITraitCollection;
    
    
    
    
    
    #pragma mark - 颜色 Class
    #pragma mark -
    NS_CLASS_AVAILABLE_IOS(2_0) @interface UIColor : NSObject <NSSecureCoding, NSCopying>
    
    /* 实例化(类方法) */
    // 设置 白色/透明度(white:0.0为黑色,1.0为白色)
    + (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
    // 设置 色调/饱和度/亮度/透明度
    + (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
    // 设置 RGB/透明度
    + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
    // 设置 sRGB(广域RGB)/透明度
    + (UIColor *)colorWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);
    // 设置 Quartz颜色
    + (UIColor *)colorWithCGColor:(CGColorRef)cgColor;
    // 设置 图片颜色
    + (UIColor *)colorWithPatternImage:(UIImage *)image;
    #if __has_include(<CoreImage/CoreImage.h>)
    // 设置 Core Image颜色
    + (UIColor *)colorWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0);
    #endif
    /* 实例化(对象方法) */
    - (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 *)initWithDisplayP3Red:(CGFloat)displayP3Red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha NS_AVAILABLE_IOS(10_0);
    - (UIColor *)initWithCGColor:(CGColorRef)cgColor;
    - (UIColor *)initWithPatternImage:(UIImage*)image;
    #if __has_include(<CoreImage/CoreImage.h>)
    - (UIColor *)initWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0);
    #endif
    
    /* 常用颜色 */
    #if UIKIT_DEFINE_AS_PROPERTIES
    @property(class, nonatomic, readonly) UIColor *blackColor;      /// 黑色(0.0 white)
    @property(class, nonatomic, readonly) UIColor *darkGrayColor;   /// 深灰色(0.333 white)
    @property(class, nonatomic, readonly) UIColor *lightGrayColor;  /// 浅灰色(0.667 white)
    @property(class, nonatomic, readonly) UIColor *whiteColor;      /// 白色(1.0 white)
    @property(class, nonatomic, readonly) UIColor *grayColor;       /// 灰色(0.5 white)
    @property(class, nonatomic, readonly) UIColor *redColor;        /// 红色(1.0, 0.0, 0.0 RGB)
    @property(class, nonatomic, readonly) UIColor *greenColor;      /// 绿色(0.0, 1.0, 0.0 RGB)
    @property(class, nonatomic, readonly) UIColor *blueColor;       /// 蓝色(0.0, 0.0, 1.0 RGB)
    @property(class, nonatomic, readonly) UIColor *cyanColor;       /// 青色(0.0, 1.0, 1.0 RGB)
    @property(class, nonatomic, readonly) UIColor *yellowColor;     /// 黄色(1.0, 1.0, 0.0 RGB)
    @property(class, nonatomic, readonly) UIColor *magentaColor;    /// 品红(1.0, 0.0, 1.0 RGB)
    @property(class, nonatomic, readonly) UIColor *orangeColor;     /// 橙色(1.0, 0.5, 0.0 RGB)
    @property(class, nonatomic, readonly) UIColor *purpleColor;     /// 紫色(0.5, 0.0, 0.5 RGB)
    @property(class, nonatomic, readonly) UIColor *brownColor;      /// 棕褐色(0.6, 0.4, 0.2 RGB)
    @property(class, nonatomic, readonly) UIColor *clearColor;      /// 透明色(0.0 white, 0.0 alpha)
    #else
    + (UIColor *)blackColor;
    + (UIColor *)darkGrayColor;
    + (UIColor *)lightGrayColor;
    + (UIColor *)whiteColor;
    + (UIColor *)grayColor;
    + (UIColor *)redColor;
    + (UIColor *)greenColor;
    + (UIColor *)blueColor;
    + (UIColor *)cyanColor;
    + (UIColor *)yellowColor;
    + (UIColor *)magentaColor;
    + (UIColor *)orangeColor;
    + (UIColor *)purpleColor;
    + (UIColor *)brownColor;
    + (UIColor *)clearColor;
    #endif
    
    /* 在当前绘图上下文中设置Color,应由子类实现 */
    // 设置颜色
    - (void)set;
    // 设置填充颜色
    - (void)setFill;
    // 设置描边颜色
    - (void)setStroke;
    
    /* 颜色检索(如果接收器具有兼容的颜色空间返回YES,否则NO) */
    // 返回该颜色的灰度分量
    - (BOOL)getWhite:(nullable CGFloat *)white alpha:(nullable CGFloat *)alpha NS_AVAILABLE_IOS(5_0);
    // 返回色彩在HSB颜色空间的分量
    - (BOOL)getHue:(nullable CGFloat *)hue saturation:(nullable CGFloat *)saturation brightness:(nullable CGFloat *)brightness alpha:(nullable CGFloat *)alpha NS_AVAILABLE_IOS(5_0);
    // 返回构成颜色的RGB颜色空间的分量
    - (BOOL)getRed:(nullable CGFloat *)red green:(nullable CGFloat *)green blue:(nullable CGFloat *)blue alpha:(nullable CGFloat *)alpha NS_AVAILABLE_IOS(5_0);
    
    // 设置颜色透明度
    - (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;
    
    /* 底层的CGColor或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
    
    @end
    
    
    
    
    
    #pragma mark - 项目提供程序 <分类>
    /*
     - 用于复制/粘贴过程中的扩展方法
     */
    @interface UIColor (UINSItemProvider) <NSItemProviderReading, NSItemProviderWriting>
    
    @end
    
    
    
    
    
    #pragma mark - 附加功能 <CIColor 分类>
    #if __has_include(<CoreImage/CoreImage.h>)
    @interface CIColor(UIKitAdditions)
    
    // 使用UIKit(或AppKit)颜色对象初始化Core Image
    - (instancetype)initWithColor:(UIColor *)color NS_AVAILABLE_IOS(5_0);
    
    @end
    #endif
    
    
    
    
    
    #pragma mark - Color名称 <分类>
    @interface UIColor (UIColorNamedColors)
    
    /**
     实例化UIColor(使用存储在命名资源中的信息创建;默认查找main bundle)
    
     @param name 姓名
     @return UIColor
     */
    + (nullable UIColor *)colorNamed:(NSString *)name NS_AVAILABLE_IOS(11_0);
    /**
     实例化UIColor
    
     @param name 姓名
     @param bundle 包
     @param traitCollection 功能集合(包括:水平/垂直/显示比例/用户界面习惯等特性)
     @return UIColor
     */
    + (nullable UIColor *)colorNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection NS_AVAILABLE_IOS(11_0);
    
    @end
    
    
    
    
    
    NS_ASSUME_NONNULL_END
    
    #else
    #import <UIKitCore/UIColor.h>
    #endif
    
    

    相关文章

      网友评论

        本文标题:UIColor.h

        本文链接:https://www.haomeiwen.com/subject/cgoxqctx.html