Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Can now create a BNColor from a hex rgb string.

I also renamed colorFromBNColor to UIColor, as this is shorter and more
consistent with Apple's style for similar methods (like UTF8String in
NSString).  I'll leave in support for the old version, for a little
while, but it is now marked as deprecated.
  • Loading branch information...
commit c4367119628cd9316594d214fbcc1f8c5e4c73e6 1 parent f7e3a7a
@tylerneylon authored
Showing with 23 additions and 1 deletion.
  1. +3 −1 BNColor.h
  2. +20 −0 BNColor.m
View
4 BNColor.h
@@ -29,12 +29,14 @@
@property (nonatomic) float value;
+ (BNColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue;
++ (BNColor *)colorFromRGBHexString:(NSString *)rgbString;
- (void)setWithHue:(float)h saturation:(float)s value:(float)v;
- (void)setFill;
- (void)setStroke;
-- (UIColor *)colorFromBNColor;
+- (UIColor *)colorFromBNColor __attribute__((deprecated)); // Use the UIColor method instead; more traditional name.
+- (UIColor *)UIColor;
- (NSString *)hexCode;
- (NSString *)decString;
View
20 BNColor.m
@@ -7,6 +7,8 @@
#import "BNColor.h"
+#import "NSObject+Be.h"
+
#define kRedKey @"r"
#define kGreenKey @"g"
#define kBlueKey @"b"
@@ -31,6 +33,20 @@ + (BNColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue {
return color;
}
++ (BNColor *)colorFromRGBHexString:(NSString *)rgbString {
+ int component[3];
+ for (int i = 0; i < 3; ++i) {
+ sscanf([[rgbString substringWithRange:NSMakeRange(i * 2, 2)] UTF8String], "%X", component + i);
+ }
+
+ BNColor *color = [BNColor beInit];
+ color.red = (component[0] / 255.0);
+ color.green = (component[1] / 255.0);
+ color.blue = (component[2] / 255.0);
+
+ return color;
+}
+
- (float)hue {
float hue, min, max;
[self findMin:&min max:&max];
@@ -129,6 +145,10 @@ - (UIColor *)colorFromBNColor {
return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}
+- (UIColor *)UIColor {
+ return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
+}
+
- (NSString *)hexCode {
return [NSString stringWithFormat:@"#%02X%02X%02X",
(int)round(self.red * 255), (int)round(self.green * 255), (int)round(self.blue * 255)];
Please sign in to comment.
Something went wrong with that request. Please try again.