diff --git a/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.h b/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.h index 4ee3beb..546147e 100644 --- a/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.h +++ b/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.h @@ -25,5 +25,6 @@ @interface HYPUIHelpers : NSObject +(NSString *)rgbTextForColor:(UIColor *)color; ++(NSString *)hexTextForColor:(UIColor *)color; @end diff --git a/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.m b/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.m index 2e1a18f..21bcc6e 100644 --- a/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.m +++ b/AttributesInspector/AttributesViewer/Helpers/HYPUIHelpers.m @@ -39,4 +39,24 @@ +(NSString *)rgbTextForColor:(UIColor *)color return nil; } ++(NSString *)hexTextForColor:(UIColor *)color +{ + CGFloat red = 0; + CGFloat green = 0; + CGFloat blue = 0; + CGFloat alpha = 0; + + if ([color getRed:&red green:&green blue:&blue alpha:&alpha]) + { + int r = round(red * 255); + int g = round(green * 255); + int b = round(blue * 255); + + NSString *hexString = [NSString stringWithFormat:@"#%02X%02X%02X", r, g, b]; + return hexString; + } + + return nil; +} + @end diff --git a/AttributesInspector/AttributesViewer/PreviewViews/HYPTextPreview.m b/AttributesInspector/AttributesViewer/PreviewViews/HYPTextPreview.m index 278f95f..5f6e1ab 100644 --- a/AttributesInspector/AttributesViewer/PreviewViews/HYPTextPreview.m +++ b/AttributesInspector/AttributesViewer/PreviewViews/HYPTextPreview.m @@ -108,6 +108,10 @@ -(void)setupWithFont:(UIFont *)font color:(UIColor *)color if (colorText) { self.colorLabel.text = [NSString stringWithFormat:@"RGBA %@", colorText]; + + UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped:)]; + self.colorLabel.userInteractionEnabled = YES; + [self.colorLabel addGestureRecognizer:tapGesture]; } else { @@ -115,4 +119,24 @@ -(void)setupWithFont:(UIFont *)font color:(UIColor *)color } } +-(void)labelTapped:(UITapGestureRecognizer *)gestureRecognizer +{ + if ([self.colorLabel.text hasPrefix:@"RGBA"]) + { + NSString *colorText = [HYPUIHelpers hexTextForColor:_textColor]; + if (colorText) + { + self.colorLabel.text = [NSString stringWithFormat:@"HEX %@", colorText]; + } + } + else + { + NSString *colorText = [HYPUIHelpers rgbTextForColor:_textColor]; + if (colorText) + { + self.colorLabel.text = [NSString stringWithFormat:@"RGBA %@", colorText]; + } + } +} + @end diff --git a/AttributesInspector/AttributesViewer/PreviewViews/HYPViewPreview.m b/AttributesInspector/AttributesViewer/PreviewViews/HYPViewPreview.m index f008c1a..3f9cb76 100644 --- a/AttributesInspector/AttributesViewer/PreviewViews/HYPViewPreview.m +++ b/AttributesInspector/AttributesViewer/PreviewViews/HYPViewPreview.m @@ -44,6 +44,10 @@ -(instancetype)initWithPreviewTargetView:(UIView *)view if (rgbText) { _colorLabel.text = [NSString stringWithFormat:@"RGBA %@", rgbText]; + + UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped:)]; + _colorLabel.userInteractionEnabled = YES; + [_colorLabel addGestureRecognizer:tapGesture]; } else { @@ -57,5 +61,24 @@ -(instancetype)initWithPreviewTargetView:(UIView *)view return self; } +-(void)labelTapped:(UITapGestureRecognizer *)gestureRecognizer +{ + if ([self.colorLabel.text hasPrefix:@"RGBA"]) + { + NSString *colorText = [HYPUIHelpers hexTextForColor:_previewTarget.backgroundColor]; + if (colorText) + { + self.colorLabel.text = [NSString stringWithFormat:@"HEX %@", colorText]; + } + } + else + { + NSString *colorText = [HYPUIHelpers rgbTextForColor:_previewTarget.backgroundColor]; + if (colorText) + { + self.colorLabel.text = [NSString stringWithFormat:@"RGBA %@", colorText]; + } + } +} @end