iOS 重新定义cell的分割线样式

来源:互联网 发布:用图表直观表达数据 编辑:程序博客网 时间:2024/06/06 11:40
实现如下: 
UITableView中将分割线样式改为None 
tableView.separatorStyle = UITableViewCellSeparator<wbr>StyleNone;</wbr>

自定义UITableViewCell中复写- (void)drawRect:(CGRect)rect方法 

- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentCont<wbr>ext(); CGContextSetFillColorWit<wbr>hColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect); //上分割线, CGContextSetStrokeColorW<wbr>ithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor); CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1)); //下分割线 CGContextSetStrokeColorW<wbr>ithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor); CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10, 1)); }</wbr></wbr></wbr></wbr>
0 0