react-native-navigation的迁移库

Color.m 995B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import "Color.h"
  2. @interface Color()
  3. @property (nonatomic, retain) UIColor* value;
  4. @end
  5. @implementation Color
  6. + (instancetype)withColor:(UIColor *)value {
  7. return [[Color alloc] initWithValue:value];
  8. }
  9. - (instancetype)initWithValue:(UIColor *)value {
  10. return [super initWithValue:value];
  11. }
  12. - (UIColor *)get {
  13. return self.value;
  14. }
  15. - (UIColor *)getWithDefaultValue:(id)defaultValue {
  16. return [super getWithDefaultValue:defaultValue];
  17. }
  18. -(NSString *)description {
  19. return [self hexStringFromColor:[self getWithDefaultValue:nil]];
  20. }
  21. - (NSString *)hexStringFromColor:(UIColor *)color {
  22. const CGFloat *components = CGColorGetComponents(color.CGColor);
  23. CGFloat r = components[0];
  24. CGFloat g = components[1];
  25. CGFloat b = components[2];
  26. return [NSString stringWithFormat:@"#%02lX%02lX%02lX",
  27. lroundf(r * 255),
  28. lroundf(g * 255),
  29. lroundf(b * 255)];
  30. }
  31. @end