【问题标题】:Prevent CAGradientLayer from Overlapping inside UIImageView on UITableViewCell防止 CAGradientLayer 在 UITableViewCell 上的 UIImageView 内重叠
【发布时间】:2014-07-02 10:36:01
【问题描述】:

我在我的cellForRowAtIndexPath 方法中使用Storyboards 在我的自定义UITableViewCell 中应用渐变,我想防止CAGradientLayer 渐变的应用重叠。我该怎么做?

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

- (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,我在其中加载图像并在其中应用渐变。

【问题讨论】:

    标签: ios objective-c uitableview gradient cagradientlayer


    【解决方案1】:

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

    cell.backgroundImage.layer.sublayers = nil;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 2012-12-04
      相关资源
      最近更新 更多