简体   繁体   中英

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 :

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.

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:

-(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.

在此输入图像描述

After some experimentation I've found solution! tableFooterView can be covered separator like this:

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. 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.

给桌子一个空页脚:

self.tableFooterView = [[UIView alloc] init]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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