dev*_*os1 1 uitableview ios automatic-ref-counting cagradientlayer
在我的表格视图控制器的以下代码中,如果我使用“库存”颜色,[UIColor blueColor]它可以正常工作,但是如果我尝试使用 RGBA 值创建自定义颜色,它会失败并且除了纯黑色之外不绘制任何东西。
这是因为 ARC 在可以使用之前释放了 CGColorRef 吗?我怎样才能让它与自定义颜色一起工作?
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setBackgroundColor:[UIColor clearColor]];
    CAGradientLayer *selectedGrad = [CAGradientLayer layer];
    selectedGrad.frame = cell.bounds;
    UIColor* colorOne = [UIColor blueColor];//[UIColor colorWithRed:96/255 green:157/255 blue:227/255 alpha:1];
    UIColor* colorTwo = [UIColor greenColor];//[UIColor colorWithRed:54/255 green:123/255 blue:201/255 alpha:1];
    NSArray* colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];
    selectedGrad.colors = colors;
    selectedGrad.locations = [NSArray arrayWithObjects:@(0.0), @(1.0), nil];
    [cell setSelectedBackgroundView:[[UIView alloc] init]];
    [cell.selectedBackgroundView.layer insertSublayer:selectedGrad atIndex:0];
}
| 归档时间: | 
 | 
| 查看次数: | 882 次 | 
| 最近记录: |