自定義 TableViewCell 的分割線
剛開始自定義 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));
}
浙公網安備 33010602011771號