如何显示带有哈希值的图像视图背景色

Mah*_*abu 1 iphone

如何显示带有哈希值的图像视图背景色。

我需要将图像视图的背景色设置为#028002。

谁能帮帮我吗,

预先谢谢你。

小智 5

我使用了下一个UIColor类别:

@implementation UIColor(Tools)

+ (UIColor *)colorWithHex:(NSInteger)hex alpha:(CGFloat)alpha {
    return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 green:((float)((hex & 0xFF00) >> 8))/255.0 blue:((float)(hex & 0xFF))/255.0 alpha:alpha];
}

@end

// Example of Usage: 
// backgroundView.backgroundColor = [UIColor colorWithHex:0xe1e1e1 alpha:1.0];
Run Code Online (Sandbox Code Playgroud)

此处无需解析字符串。