简体   繁体   English

UITableView部分中的iOS7最后一个单元格强制全宽分隔符

[英]iOS7 last cell in UITableView section forces full width separator

The UITableView below has custom UITableViewCells and I can adjust the separators fine using this line in the custom UITableViewCell : 下面的UITableView有自定义UITableViewCells ,我可以使用自定义UITableViewCell中的这一行调整分隔符:

self.separatorInset = UIEdgeInsetsMake(0, kDefaultSeparatorLeftInset, 0, 0);

However the cell at the bottom of the section has a default separator that overrides the custom UIEdgeInsets that I set. 但是,该部分底部的单元格有一个默认分隔符,它会覆盖我设置的自定义UIEdgeInsets

I'd like all the separators to be the same width, is there any way of doing this without redrawing the separators manually? 我希望所有分隔符的宽度相同,有没有办法在不重新绘制分隔符的情况下执行此操作?

在iOS7中使用宽截面分隔符的UITableView

After some experimentation I've found the only real solution is to set the UITableViewStyle to UITableViewStylePlain and set empty footers using: 一些实验后,我发现的唯一真正的解决办法是设定UITableViewStyleUITableViewStylePlain和设置使用空页脚:

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc] initWithFrame:CGRectZero];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01f;
}

This will not be a satisfactory solution for some, because UITableViewStylePlain does not provide all of the features of UITableViewStyleGrouped , but it gives me the section without the full-width separator. 这会不会是一些令人满意的解决方案,因为UITableViewStylePlain不提供所有的功能UITableViewStyleGrouped ,但它给了我没有全宽分离的部分。

在此输入图像描述

After some experimentation I've found solution! 经过一些实验,我找到了解决方案! tableFooterView can be covered separator like this: tableFooterView可以像这样覆盖分隔符:

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
UIView *v2 = [[UIView alloc] initWithFrame:CGRectMake(0, -1, 320, 2)];
v2.backgroundColor = [UIColor whiteColor];
v.backgroundColor = [UIColor whiteColor];
[v addSubview:v2];
self.tableView.tableFooterView = v;

Use the separatorInset property on the tableView itself, instead of on individual cells. 在tableView本身上使用separatorInset属性,而不是在单个单元格上。 The tableView's separatorInset sets the default inset, which can be overridden by cells, as well as the inset for the "extra" cells at the bottom. tableView的separatorInset设置默认插入,可以由单元格覆盖,以及底部“额外”单元格的插入。

给桌子一个空页脚:

self.tableFooterView = [[UIView alloc] init]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM