iphone - 具有 clearColor 背景的 UITableView 部分?

标签 iphone objective-c ios cocoa-touch

我有一个带有径向渐变背景的 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/

相关文章:

ios - 无论是否在托管上下文 iOS 上调用保存,Core Data 中的实体是否会保留其状态?

iphone - 从应用程序包读取文本文件

c# - iOS C# 将 JSON 数据添加到 tableView

ios - scrollview 在 autolayout xcode 6.4 中不滚动

ios - 在 Objective-C 中为 swift 类使用多参数 init 的语法

ios - 分配自定义字体时出现异常

iphone - DataMan iPhone 应用程序如何在后台工作

iphone - 需要对 iphone 中的术语进行解释

c++ - C++ 中的 Objective C——超出范围

objective-c - 有没有办法通过绑定(bind)使 TextView 和 slider 与 CGRect 的浮点值保持同步?