【问题标题】:How to change the background of a UIimageview to hex value如何将 UIimageview 的背景更改为十六进制值
【发布时间】:2011-07-05 02:52:47
【问题描述】:

我想更改 UIimageview 的背景颜色。我知道如何做到这一点

 ColorBox.backgroundColor = [UIColor blueColor];

但是,我的程序要求将 backgroundColor 设置为十六进制颜色值。如何设置为 Hex 颜色而不是 UIimage 文本颜色?

【问题讨论】:

    标签: iphone objective-c cocoa-touch


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      假设您有红色、绿色和蓝色的单独十六进制值。这应该可以。

      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?

      【讨论】:

      • 每当我使用它时,我都不会得到正确的颜色。每当我将超过 1 种颜色超过 0% 时,它会立即变成粉红色,因此 10% 的蓝色和 60% 的红色 = 粉红色 255% 的蓝色和 10% 的红色 = 粉红色
      猜你喜欢
      • 2016-04-02
      • 2023-03-14
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      • 2011-09-07
      • 2022-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多