释放双眼,带上耳机,听听看~!
一,使UITableViewCell分割线靠左,不要留间距;
方法一:
-(void)viewDidLayoutSubviews {
if ([_tableview respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableview setSeparatorInset:UIEdgeInsetsZero];
}
if ([_tableview respondsToSelector:@selector(setLayoutMargins:)]) {
[_tableview setLayoutMargins:UIEdgeInsetsZero];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
方法二:
//第一步:
//UITableView去掉自带系统的分割线
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//第二步:
//在自定义的UITableViewCell里重写drawRect:方法
#pragma mark - 绘制Cell分割线
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);
//上分割线,
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:198/255.0 green:198/255.0 blue:198/255.0 alpha:1].CGColor);
CGContextStrokeRect(context, CGRectMake(0, 0, rect.size.width, 1));
//下分割线
CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:198/255.0 green:198/255.0 blue:198/255.0 alpha:1].CGColor);
CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}
二,设置cell分割线距离左边的距离
#pragma mark -- 设置cell分割线距离左边的距离
- (void)viewDidLayoutSubviews{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]){
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 85, 0, 0)];
}
}