美文网首页
解决tableview的分割线短一截

解决tableview的分割线短一截

作者: 哆啦_ | 来源:发表于2016-06-06 15:15 被阅读43次

- (void)viewDidLayoutSubviews

{

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)];

}

}

- (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];

}

}

如果需要整个项目的tableView的分割线都与左对齐 可以在appdelete里面添加如下代码:

- (void)setTableViewAppearance

{

[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];

[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];

[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {

[[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];

[[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];

[[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];

}

}

这样整个项目所有的tableView的样式都设置好了

相关文章

网友评论

      本文标题:解决tableview的分割线短一截

      本文链接:https://www.haomeiwen.com/subject/lltddttx.html