我正在绘制自定义单元格,以实现我想要的某种外观。但是,我想根据单元格是否选择来执行不同的绘图。我真的不只是想要默认的颜色。自定义单元格选中
我改变内容的看法背景色在这个方法的观点:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
然而,它只是没有正确显示,主要是它没有考虑到附带,只是有色,直到辅助指标。有没有更好的方法来实现这一点?
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
// Background
CGContextSetFillColorWithColor(context, CELL_BACKGROUND_COLOR);
CGContextMoveToPoint(context, 0.0f, 0.0f);
CGContextAddLineToPoint(context, rect.size.width, 0.0f);
CGContextAddLineToPoint(context, rect.size.width, rect.size.height);
CGContextAddLineToPoint(context, 0.0f, rect.size.height);
CGContextClosePath(context);
CGContextFillPath(context);
// Top line
CGContextSetStrokeColorWithColor(context, CELL_TOP_LINE_COLOR);
CGContextSetLineWidth(context, CELL_LINE_WIDTH);
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextMoveToPoint(context, 0.0f, 0.0f);
CGContextAddLineToPoint(context, rect.size.width, 0.0f);
CGContextStrokePath(context);
//Bottom line
CGContextSetStrokeColorWithColor(context, CELL_BOTTOM_LINE_COLOR);
CGContextSetLineWidth(context, CELL_LINE_WIDTH);
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextMoveToPoint(context, 0.0f, rect.size.height);
CGContextAddLineToPoint(context, rect.size.width, rect.size.height);
CGContextStrokePath(context);
}
我想那不过,当我切换屏幕时,电池将改变相同的颜色,我想不出一个有效的方式来处理这个 – Vikings
你尝试通过强制选定单元格的重新划分任何机会 - 可能在你选择的单元格上有一个setNeedsDisplay。只是一个建议。 – tiguero
是的,这种方法的问题是当你选择一个单元格时,你将手指放在你选择的位置,但是单元格不会突出显示,直到你让手指离开屏幕,不确定是否有方法 – Vikings