UITableView的背景下是可见单元格时,行行动都显示
问题描述:
我UITableView
与白色节头和黑暗的牢房。表格背景也是白色的。这样做是让节头时看表弹跳不错:UITableView的背景下是可见单元格时,行行动都显示
我增加了几个动作(UITableViewRowAction
)的行此表。然而,有一个问题:由于行是黑暗的,当我刷卡显示的行编辑行为,有第一个动作之间的白色差距:
(请注意,这两种细胞及其内容视图在XIB文件中设置相同的深色背景颜色。)
在检查视图层次结构后,我发现在显示操作按钮后,单元格会缩小,而我通过此间隙看到的是实际的表格视图。
因为我无法改变我尝试添加自定义背景图,以它下面的所有其他视图表视图的背景:
self.tableBackgroundView = [[UIView alloc] initWithFrame:self.tableView.bounds];
self.tableBackgroundView.backgroundColor = [UIColor redColor];
self.tableBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleSize;
[self.tableView addSubview:self.tableBackgroundView];
[self.tableView sendSubviewToBack:self.tableBackgroundView];
然而,它没有很好地工作。
是否有任何其他方式来“隐藏”细胞和它们的编辑行为之间的空白?
答
我管理通过添加背景内tableView:willDisplayCell:
(每单元之一)的每个小区后面克服这个。
这是我的最终代码:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
// Remove background gaps on the left and right sides of row separators on iOS < 10.
cell.backgroundColor = cell.contentView.backgroundColor;
// Remove another gap in row background when swiping in to the left to start editing.
CGRect cellFrame = [cell convertRect:cell.bounds toView:tableView];
UIView *backgroundView = self.cellBackgroundViews[indexPath];
if (backgroundView == nil) {
backgroundView = [[UIView alloc] init];
self.cellBackgroundViews[indexPath] = backgroundView;
}
backgroundView.frame = CGRectInset(cellFrame, 0, -1);
backgroundView.backgroundColor = cell.contentView.backgroundColor;
[self.tableView addSubview:backgroundView];
[self.tableView sendSubviewToBack:backgroundView];
}
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
UIView *backgroundView = self.cellBackgroundViews[indexPath];
[backgroundView removeFromSuperview];
}
@KKRocks你是什么意思?如果你在谈论的编辑和清除按钮他们是'UITableViewRowAction':https://developer.apple.com/reference/uikit/uitableviewrowaction – iosdude
是的,我知道,但我想知道如何添加此按钮......把这些代码所以我可以理解你的问题。 – KKRocks