1

テーブル ビュー コントローラーの次のコードでは、「ストック」カラーを使用すると[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];
}
4

2 に答える 2

5

問題は、それを行う96/255と、値が int として解釈され、結果が 0 になることです。

96.0/255.0UIColor を作成するときと同じように値を書き込んでみてください

于 2013-10-28T18:45:57.073 に答える
0

これは、RGB カラーを追加する正しい方法です。

 [UIColor colorWithRed:0x63/255.0 green:0x4E/255.0 blue:0x42/255.0 alpha:1]
于 2013-10-28T18:46:43.297 に答える