14

UITableViewCellsのセルの背景を設定しようとしていますが、UIAccessoryViewの背景色に苦労しています。変わりません。

UIAccessoryViewの背景色を透明(または実際には他の色)にするのを手伝ってくれる人はいますか?

これは私のコードです

cell.textLabel.backgroundColor = [UIColor clearColor];
cell.accessoryView.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

if(indexPath.row % 2) {
     cell.contentView.backgroundColor = [UIColor clearColor];
}
else {
    cell.contentView.backgroundColor = [UIColor redColor];
}

これが問題を説明する画像です

UIAccessoryViewは背景色を変更しません。

4

3 に答える 3

46

backgroundViewUITableViewCellのプロパティを設定する必要があります。例えば:

UIView* myBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
myBackgroundView.backgroundColor = [UIColor redColor];
myCell.backgroundView = myBackgroundView;

赤いグラデーションの背景など、もっと凝ったものが必要な場合は、にグラデーションを描画するUIViewのサブクラスを実装し、drawRect:それをbackgroundViewとして使用します。

selectedBackgroundView選択したテーブルセルのカスタムルックが必要な場合は、プロパティを設定することもできます。

于 2011-03-19T10:20:04.820 に答える
4

機能中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

次のコードを使用します

cell.contentView.superview.backgroundColor = [UIColor redColor];

詳細についてはリファレンス

于 2012-11-29T12:49:08.033 に答える
0

カスタムクラスで変更したい場合は、UITableViewCell次を使用できます。

override func layoutSubviews() {
    super.layoutSubviews()
    self.backgroundColor = UIColor.whiteColor()
}

内部の背景を変更するawakeFromNib()か、init?(coder aDecoder: NSCoder)機能しません!

于 2016-04-10T01:51:44.483 に答える