在控制器中
切记:不要设置下面语句
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//分割线inset
@property (nonatomic, assign) UIEdgeInsets insets;
//设置左右可以达到分割线不水平顶置
self.insets = UIEdgeInsetsMake(0, 0, 0, 0);
-(void)viewDidLayoutSubviews {
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:self.insets];
}
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[_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];
}
}
网友评论