【发布时间】: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