0

我在我的方法中UITableViewCell使用我的自定义应用渐变,我想防止我的渐变应用重叠。我怎样才能做到这一点?StoryboardscellForRowAtIndexPathCAGradientLayer

这是我用来防止重叠的当前代码,但渐变仅适用于最新indexPath加载的UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VideoCell" forIndexPath:indexPath];

    if (!gradientLayer) {
        gradientLayer = [CAGradientLayer layer];
    }
    gradientLayer.frame = cell.backgroundImage.bounds;
    gradientLayer.colors =  @[(id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor];
    [cell.backgroundImage.layer insertSublayer:gradientLayer atIndex:0];

    return cell;
}

cell.backgroundImage只是一个UIImageView加载图像并在其中应用渐变的地方。

4

1 回答 1

0

我找到了有效的答案。在应用渐变之前,我只是将我的 backgroundImage 子层设置为 nil。

cell.backgroundImage.layer.sublayers = nil;
于 2015-01-21T10:32:35.897 回答