tableviewcell

UITableViewCell分割线

2016-09-02  本文已影响26人  iOS_Developer

1、去除UITableView空白的多余的分割线

self.myTableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
在开发过程中,UITableViewCell的分割线左边缺失一部分很让人恼火,有时又有可能让分割线居中.第一种解决办法是:将系统分割线隐藏,自己再画一条.
第二种解决办法是:修改系统的分割线,将分割线拉长或缩短.
第一种解决方法就不说了,相信大家都会,再次说明下第二种.

@interface MATableViewController ()
@property (nonatomic, assign) UIEdgeInsets insets;
@end
@implementation MATableViewController

pragma mark 用于将cell分割线补全

-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{ [self.tableView setSeparatorInset:self.insets];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{ [self.tableView setLayoutMargins:self.insets];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell )cell forRowAtIndexPath:(NSIndexPath)indexPath{
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
{ [cell setLayoutMargins:self.insets];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
{ [cell setSeparatorInset:self.insets];
}
}


效果如下

![Paste_Image.png](http:https://img.haomeiwen.com/i1955259/f21d0903d6157133.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

参考:http://www.jianshu.com/p/1ca0cc858bce
上一篇 下一篇

猜你喜欢

热点阅读