UITableViewCell自定义分割线

时间:2015-01-30 22:40:54   收藏:0   阅读:175

产品设计今天要求cell的分割线不能是整个屏幕的长度,这时候我们有两种方法可以解决

方法一就是自己写一个label放在cell上

方法二就是自定义一个分割线,方法如下

首先我们要去掉cell默认的分割线,设为none

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

然后实现- (void)drawRect:(CGRect)rect方法

- (void)drawRect:(CGRect)rect{

//首先获得上下文

 CGContextRef context = UIGraphicsGetCurrentContext();

  CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);  

  CGContextFillRect(context, rect);

//定义分割线的颜色

CGContextSetStrokeColorWithColor(context, [UIColor lightGrayColor].CGColor);

//定义分割线的坐标

 CGContextStrokeRect(context, CGRectMake(125, rect.size.height, rect.size.width - 10, 1));

这里改一下纵坐标(-1)就是上分割线

}


也可以参考这里一些专业说法:http://www.awnlab.com/archives/2463.html

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!