我想更改我的UIimageview的背景颜色。我知道如何做到这一点如何将UIimageview的背景更改为十六进制值
ColorBox.backgroundColor = [UIColor blueColor];
但是,我的程序要求将backgroundColor设置为十六进制颜色值。我如何设置为十六进制颜色而不是UIimage文本颜色?
我想更改我的UIimageview的背景颜色。我知道如何做到这一点如何将UIimageview的背景更改为十六进制值
ColorBox.backgroundColor = [UIColor blueColor];
但是,我的程序要求将backgroundColor设置为十六进制颜色值。我如何设置为十六进制颜色而不是UIimage文本颜色?
假设您具有红色,绿色和蓝色的单独十六进制值。这应该工作。
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?
每当我用这个我没有得到正确的颜色出来。任何时候我把超过0%的颜色都超过1%,它会立即变成粉红色 10%蓝色和60%红色=粉色 255%蓝色和10%红色=粉色 –
您是否会发布您的代码? – Dash
我知道了谢谢你这是一个类型转换的问题。 –