0

このコードを使用して、セルの背景ビューの色をカスタマイズしています。

UIColor *cellBackgroundColor = [UIColor colorWithRed:255.0 green:255.0 blue:255.0 alpha:1.0];
cell.contentView.backgroundColor = cellBackgroundColor;

問題は、それが機能しないということです。ただし、このコードは完全に正常に機能します。

cell.contentView.backgroundColor = [UIColor redColor];

ここでの問題は何ですか?セルの色を好みに合わせてカスタマイズすることはできませんか?それとも私は何か間違ったことをしていますか?

4

5 に答える 5

2

変更するだけです:

UIColor *cellBackgroundColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0];
cell.contentView.backgroundColor = cellBackgroundColor;
于 2013-01-22T08:35:14.403 に答える
2

このデリゲートでセルの背景を設定する必要があります:-

- (void)tableView: (UITableView*)tableView
  willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{

   // UIImage *img = [UIImage imageNamed:@"button.png"];  // get your background image

    UIColor *cellBackgroundColor = [UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:1.0]; //if you want to set color then use this line

  //  UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
    cell.backgroundColor = cellBackgroundColor;
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}

あなたのテーブルは次のようになります:-

ここに画像の説明を入力してください

RGBカラーを取得し、iPhoneのUIColorで正規化する

Your values are between 0 and 255. Use them to create a UIColor:

    float r; float g; float b; float a;

    [UIColor colorWithRed:r/255.f
                    green:g/255.f
                     blue:b/255.f    
                    alpha:a/255.f];
于 2013-01-22T08:36:13.157 に答える
1
cell.backgroundView.backgroundColor

カスタムビューを作成し、完全な背景ビューを変更できます

UIView *backgroundViewForCell = [[[UIView alloc] init] autorelease];
backgroundViewForCell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"row-bg.png"]];
UIView *selectedBackgroundViewForCell = [[[UIView alloc] init] autorelease];
selectedBackgroundViewForCell.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:.2];
cell.backgroundView = backgroundViewForCell;
cell.selectedBackgroundView = selectedBackgroundViewForCell;
于 2013-01-22T08:35:45.650 に答える
1

cell.contentView.backgroundColor = [UIColor clearColor]色を設定する前に追加できるかもしれません。

その理由は、背景ビューが下部にあるためです。コンテンツビューが一番上にあります。

その他の論理的IS

UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];

myBackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1];

[cell.contentView addSubview:myBackView];

[myBackView release];
于 2013-01-22T08:40:34.873 に答える
0

あなたは正しい方向に進んでいます。カラーコードをこれに置き換えるだけです

UIColor *cellBackgroundColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0];

プログラミングをお楽しみください!

于 2013-01-22T08:38:50.387 に答える