我有一个带有径向渐变背景的 ViewController。在里面我有一个带有单元格和部分的 UITableView。现在我想在滚动时显示表格 View 后面的渐变。问题是,当该部分锁定在顶部时,您可以看到该部分后面的单元格。我会设置部分背景颜色,但如果我这样做,它与径向渐变背景不匹配。有没有办法在保持 clearColor 背景的同时让单元格夹在这些部分下面?
最佳答案
无需创建自己的标题 View 即可获得透明部分标题的简单方法。
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
if ([view isKindOfClass:[UITableViewHeaderFooterView class]]) {
UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView *)view;
headerView.contentView.backgroundColor = [UIColor clearColor];
headerView.backgroundView.backgroundColor = [UIColor clearColor];
}
}
这段代码在 iOS 7 中运行良好。
编辑 我知道这有点晚了,但除此之外你还必须添加 2 行以确保 uitableview 的背景颜色(和背景 View 的背景颜色?)也清晰。
tableView.backgroundColor = [UIColor clearColor];
tableView.backgroundView.backgroundColor = [UIColor clearColor];
关于iphone - 具有 clearColor 背景的 UITableView 部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12751489/