我的子類的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