iOS开发:iOS TableViewCell自定义分割线

来源:互联网 发布:mac怎么下b站视频 知乎 编辑:程序博客网 时间:2024/05/16 05:09
实现如下: 
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
    原创粉丝点击