在我的编辑器中,我有一个标签,在UITapGestureRecognizer上,我需要获取文本的颜色
NSLog(@"Fontcolor---- %@",sanlabel.textColor);但这段代码返回给我
UIDeviceRGBColorSpace 0.686275 1 1 1我如何获得正确格式的颜色代码,以便我可以将其用作
UIColorFromRGB(0X2c3836)发布于 2014-01-23 19:30:19
您可以使用此方法(取自here):
- (NSString *) htmlFromUIColor:(UIColor *)_color {
if (CGColorGetNumberOfComponents(_color.CGColor) < 4) {
const CGFloat *components = CGColorGetComponents(_color.CGColor);
_color = [UIColor colorWithRed:components[0] green:components[0] blue:components[0] alpha:components[1]];
}
if (CGColorSpaceGetModel(CGColorGetColorSpace(_color.CGColor)) != kCGColorSpaceModelRGB) {
return [NSString stringWithFormat:@"#FFFFFF"];
}
return [NSString stringWithFormat:@"#%02X%02X%02X", (int)((CGColorGetComponents(_color.CGColor))[0]*255.0), (int)((CGColorGetComponents(_color.CGColor))[1]*255.0), (int)((CGColorGetComponents(_color.CGColor))[2]*255.0)];
}https://stackoverflow.com/questions/21306740
复制相似问题