Last active
November 9, 2020 09:06
-
-
Save cntrump/3b9bebd99f23601034f2c70521ddacf3 to your computer and use it in GitHub Desktop.
UIColor Extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <UIKit/UIKit.h> | |
| NS_ASSUME_NONNULL_BEGIN | |
| @interface UIColor (Extension) | |
| + (instancetype)colorWithRGB:(NSUInteger)value alpha:(CGFloat)alpha; | |
| @end | |
| #ifndef HexColor | |
| # define HexColor(x) [UIColor colorWithRGB:(NSUInteger)(x) alpha:1] | |
| # define HexColorA(x, a) [UIColor colorWithRGB:(NSUInteger)(x) alpha:a] | |
| #endif | |
| NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "UIColor+Extension.h" | |
| @implementation UIColor (Extension) | |
| + (instancetype)colorWithRGB:(NSUInteger)value alpha:(CGFloat)alpha { | |
| CGFloat r = ((value & 0xff0000) >> 16) / 255.0; | |
| CGFloat g = ((value & 0xff00) >> 8) / 255.0; | |
| CGFloat b = (value & 0xff) / 255.0; | |
| return [UIColor colorWithRed:r green:g blue:b alpha:alpha]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment