iOS技巧天生不是作曲家iOS知识

UITableView完美分割线

2016-05-22  本文已影响1771人  小小小阿博er
//设置tableview的分割线没有开头的间距

//view布局完子控件的时候调用
- (void)viewDidLayoutSubviews
{
//iOS7只需要设置SeparatorInset(iOS7开始有的)就可以了,但是iOS8的话单单只设置这个是不行的,还需要设置LayoutMargins(iOS8开始有的)
   if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
       [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
   }

   if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
       [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
   }
}
//cell即将展示的时候调用
- (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];
   }
}


截图1.png 截图2.png
上一篇 下一篇

猜你喜欢

热点阅读