根据数组iOS中的值更改单元格的颜色
任何想法这是什么问题:
if ([status isEqualToString: @"green"]) [[cell contentView] setBackgroundColor: [UIColor colorWithRed: 200 green: 191 blue: 231 alpha: 1]];
我在@implementation中定义了数组。 Xcode显示以下错误:
NSArray
没有可见的@interface
声明select器isEqualToString:
这个想法是,当数组中的string值等于string“green”( colorWithRed
中的值不是实际的绿色)时,单元格背景变为绿色,
提前致谢。
问题在于RGB值。
在正常的RGB是在0到255之间
但
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
取值在0.0到1.0之间
所以你可以这样做:
[[cell contentView] setBackgroundColor: [UIColor colorWithRed: 200.0/255.0 green: 191.0/255.0 blue: 231.0/255.0 alpha: 1]];
看看这里colorWithRed:green:blue:alpha:
看来, status
是一个NSArray
你不能比较,特别是使用isEqualToString一个string。 尝试使用像[status objectAtIndex:0];
或将status
更改为NSString
此外CRDave是正确的,你应该将你所有的颜色数字除以255.那么他们是CGFloats,我相信在技术上255.0否则数字将四舍五入,并导致每次0(或1)。
如果你想要一个真正的绿色,你也可以使用[UIColor greenColor];
(除非你想要一个特定的绿色)
- PhoneGap启动图片iOS Apple Store提交
- drawInRect:withAttributes vs drawInRect:withFont:lineBreakMode:alignment
- 如何从iTunes中设置声音本地通知?
- 在iOS应用程序中获取一个人的Facebook公开个人资料
- 调整图像大小Objective-C
- 如何改善您的IGListCollectionView
- 无法使用types为“(NSMutableURLRequest,(_,_,_)throws – > _”)的参数列表调用“dataTaskWithRequest”
- iOS加载动态图层蒙版(即代码外部提供图层蒙版)
- parsing+条纹iOS main.js