iOS - tableviewcell分割线不对齐以及取消分割线


  • 取消分隔线代码属于tableview的属性设置如下
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  • 分割线不对齐左侧默认留出15点空白,对齐设置代码:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{
     [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
 {
     [self.tableView setLayoutMargins:UIEdgeInsetsZero];
}

//然后在UITableView的代理方法中加入以下代码
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
       {
          [cell setSeparatorInset:UIEdgeInsetsZero];
       }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
       {
         [cell setLayoutMargins:UIEdgeInsetsZero];
       }
}
  • 不对齐设置方法二:
self.tableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);
  • 如图:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM