您的位置:首页 > 移动开发 > IOS开发

iOS TableViewCell自定义分割线

2014-12-01 15:08 507 查看
http://www.software8.co/caozuoxt/ios/2491.html

产品设计的要求cell的分割线长度不用是整个屏幕宽,并且设计要求分割线为2px(两条),上下不同色。

实现如下:

UITableView中将分割线样式改为None

Java代码:

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

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

Java代码:

- (void)drawRect:(CGRect)rect

{

CGContextRef context = UIGraphicsGetCurrentContext();

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

CGContextFillRect(context, rect);

//上分割线,

CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"ffffff"].CGColor);

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

//下分割线

CGContextSetStrokeColorWithColor(context, [UIColor colorWithHexString:@"e2e2e2"].CGColor);

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: