我在我的方法中UITableViewCell
使用我的自定义应用渐变,我想防止我的渐变应用重叠。我怎样才能做到这一点?Storyboards
cellForRowAtIndexPath
CAGradientLayer
这是我用来防止重叠的当前代码,但渐变仅适用于最新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
加载图像并在其中应用渐变的地方。