iOS开发_取出UIColor上对应rgba的值
原创
©著作权归作者所有:来自51CTO博客作者wx6103b5205e184的原创作品,请联系作者获取转载授权,否则将追究法律责任
UIColor+Extension.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIColor (Extension)
@property(nonatomic, assign, readonly) CGFloat red;
@property(nonatomic, assign, readonly) CGFloat green;
@property(nonatomic, assign, readonly) CGFloat blue;
@property(nonatomic, assign, readonly) CGFloat alpha;
@end
NS_ASSUME_NONNULL_END
UIColor+Extension.m
#import "UIColor+Extension.h"
@implementation UIColor (Extension)
- (CGFloat)red {
CGFloat r = 0, g, b, a;
[self getRed:&r green:&g blue:&b alpha:&a];
return r;
}
- (CGFloat)green {
CGFloat r, g = 0, b, a;
[self getRed:&r green:&g blue:&b alpha:&a];
return g;
}
- (CGFloat)blue {
CGFloat r, g, b = 0, a;
[self getRed:&r green:&g blue:&b alpha:&a];
return b;
}
- (CGFloat)alpha {
return CGColorGetAlpha(self.CGColor);
}
@end
作者: CH520