我的子类的UITableViewCell到单元格的背景颜色设置为一种颜色,我需要:UITableViewCell的背景色问题
.H
@interface DataViewCustomCell : UITableViewCell {
UIColor* cellColor;
UIColor* standardColor;
}
- (void) setCellColor: (UIColor*)color;
@end
.M
@implementation DataViewCustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void) setCellColor: (UIColor*)color
{
cellColor = color;
}
- (void) spreadBackgroundColor: (UIView*)that withColor: (UIColor*)bkColor
{
NSEnumerator *enumerator = [that.subviews objectEnumerator];
id anObject;
while (anObject = [enumerator nextObject]) {
if([anObject isKindOfClass: [UIView class]])
{
((UIView*)anObject).backgroundColor = bkColor;
[self spreadBackgroundColor:anObject withColor:bkColor];
}
}
}
- (void) layoutSubviews {
[super layoutSubviews]; // layouts the cell as UITableViewCellStyleValue2 would normally look like
if(!self.selected && NULL != cellColor)
{
[self spreadBackgroundColor:self withColor:cellColor];
}
}
- (void)dealloc
{
[super dealloc];
}
@end
当我打电话setCellColor与我想要的颜色一切都很顺利,但是当我还没有找到方法来设置原始颜色时:当我使用UITableViewStylePlain样式设置[UIColor clearColor]
时,结果不太好看。
我怎样才能达到良好的效果,且不欠缺细胞分离机线?
它不工作 – edo42 2011-06-14 16:49:18
它有什么作用?根本改变颜色? – James 2011-06-14 16:57:22
我有一些内存问题,但我修好了,它返回灰色 – edo42 2011-06-14 17:00:04