【发布时间】:2015-05-04 17:11:03
【问题描述】:
我想用RGB颜色来设置UIButton的背景颜色。
我有很多UIButtons,所以我决定创建一个自定义类。但是当我尝试使用colorWithRed 时出现错误。
第一个代码:
[self.layer setBackgroundColor:[UIColor colorWithRed:60/255.0f green:146/255.0f blue:180/255.0f alpha:1.0f]];
错误
第二个代码
self.layer.backgroundColor = [UIColor colorWithRed:60/255.0f green:146/255.0f blue:180/255.0f alpha:1.0f];
错误
【问题讨论】:
-
阅读错误信息!图层的背景颜色是 CGColor,而不是 UIColor。
-
@matt 如何使用 RGB 转 CGColor
标签: objective-c ios7 uibutton xcode6 uicolor