天天看点

ios7:tableview的separate(分割线)设置

ios7 后,tableview的分割线离屏幕左边有一段距离,要设置成为离屏幕没有距离,添加如下代码:

方法一:

-(void)viewDidLayoutSubviews

{

   if ([table respondsToSelector:@selector(setSeparatorInset:)]) {

        [tablesetSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

    }

   if ([tablerespondsToSelector:@selector(setLayoutMargins:)]) {

        [tablesetLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];

    }

}

在 - ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath里面,添加如下代码:

if ([CellrespondsToSelector:@selector(setSeparatorInset:)]) {

        [CellsetSeparatorInset:UIEdgeInsetsZero];

    }

   if ([CellrespondsToSelector:@selector(setLayoutMargins:)]) {

        [CellsetLayoutMargins:UIEdgeInsetsZero];

    }

当吧tableview的样式设为plain时,会有多余的分割线出现,设为group样式则不会有了,在设置footer和header高度时,可以在- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)sectionNS_AVAILABLE_IOS(7_0);

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)sectionNS_AVAILABLE_IOS(7_0);

里面设置高度。

方法二:

使用UIAppearance,在程序开始的时候设置全局默认外观,不错的方法

ios7:tableview的separate(分割线)设置