iOS7 和 iOS8 中tableview cell分割线左对齐的方法不一样,特此为以后需要做笔记。
iOS7 中方法很简单,只需要设置 _table.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
而iOS8 中方法需要写一段代码:
-(void)viewDidLayoutSubviews { if ([_table respondsToSelector:@selector(setSeparatorInset:)]) { [_table setSeparatorInset:UIEdgeInsetsZero]; } if ([_table respondsToSelector:@selector(setLayoutMargins:)]) { [_table 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]; } }
时间: 2024-09-28 22:21:23