
刚开始自定义 tableViewCell 的时候,用的是直接在 cell 上加一张 imageView 的方法,如果在点击 cell 的时候有页面的跳转,这样做没什么问题,但是,如果在点击 cell 的时候有选中效果,并且没有页面跳转的话,就会发现,分割线也会出现隐藏之后再显示的效果,这样显然不符合我们的预期效果,今天发现一个解决的办法,在自定义的 cell 里面重写 drawRect 方法:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:227/255.0 green:229/255.0 blue:233/255.0 alpha:1].CGColor);
CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}