UITableViewCell с аксессуаром - PullRequest
0 голосов
/ 28 марта 2012

Я получил приложение с UITableView. Каждая клетка имеет аксессуар. Но я не могу установить backgroundColor для этих ячеек.

enter image description here

Я попытался установить backgrounColors следующим образом:

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

Но работает только contentView. Как мне это сделать? Thnx

1 Ответ

2 голосов
/ 28 марта 2012

Второй способ cell.backgroundView.backgroundColor = [UIColor redColor]; не так уж и плох. К сожалению, нет backgroundView, пока вы его не создадите. Вы должны создать UIView и установить его в качестве фона ячейки.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];
    UIView *background = [[UIView alloc] initWithFrame:CGRectZero];
    background.backgroundColor = [UIColor redColor];
    cell.backgroundView = background;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...