在iOS 7 中,我们可能会这样设置UItableview,把分割线右移的问题解决掉。
#ifdef __IPHONE_7_0
if ([tableViewProj respondsToSelector:@selector(separatorInset)]) {
[tableViewProj setSeparatorInset:UIEdgeInsetsZero];
}
#endif
但是在iOS8中就没有这么灵了。解决办法是:首先在viewDidLoad方法加入以下代码:
if ([ tableViewProj respondsToSelector:@selector(setSeparatorInset:)]) {
[tableViewProj setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableViewProj respondsToSelector:@selector(setLayoutMargins:)]) {
[tableViewProj 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];
}
}

本文介绍了如何在iOS中调整UITableView的分割线和布局边距,以实现更佳的视觉效果。通过在viewDidLoad方法中及UITableView的代理方法中加入特定代码,可以有效地解决iOS7及之后版本中出现的分割线位置偏移问题。
4493

被折叠的 条评论
为什么被折叠?



