【发布时间】:2011-07-05 02:52:47
【问题描述】:
我想更改 UIimageview 的背景颜色。我知道如何做到这一点
ColorBox.backgroundColor = [UIColor blueColor];
但是,我的程序要求将 backgroundColor 设置为十六进制颜色值。如何设置为 Hex 颜色而不是 UIimage 文本颜色?
【问题讨论】:
标签: iphone objective-c cocoa-touch
我想更改 UIimageview 的背景颜色。我知道如何做到这一点
ColorBox.backgroundColor = [UIColor blueColor];
但是,我的程序要求将 backgroundColor 设置为十六进制颜色值。如何设置为 Hex 颜色而不是 UIimage 文本颜色?
【问题讨论】:
标签: iphone objective-c cocoa-touch
【讨论】:
假设您有红色、绿色和蓝色的单独十六进制值。这应该可以。
int red = [[NSString stringWithFormat:@"%d", redHex] intValue];
int green = [[NSString stringWithFormat:@"%d", greenHex] intValue];
int blue = [[NSString stringWithFormat:@"%d", blueHex] intValue];
[UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1]
或者使用它来解析字符串: How can I convert RGB hex string into UIColor in objective-c?
【讨论】: