#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
#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