我有一个关于 UITableView 的问题...
我有一个 UITableViewController 并且创建了一个自定义单元格。
当我可视化 tableView 时,我在分隔线之前看到了一点空白,正如您在这个屏幕截图中看到的那样:
为什么?这是默认的可视化吗?
我可以改变一些东西来删除这个白色的左填充吗?
iOS 7 中默认提供前导空格,即使对于自定义单元格也是如此。
查看此属性separatorInset
UITableviewCell 删除/添加单元格行分隔符两端的白色间距。
// 删除空格
cell.separatorInset = UIEdgeInsetsZero;
或者,在 UITableView 级别,您可以使用此属性 -
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { // Safety check for below iOS 7
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
更新 - 以下代码适用于 iOS 7 和 iOS 8:
-(void)viewDidLayoutSubviews
{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(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];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)