Подтвердить что ты не робот

Прозрачный фон UITableViewCell (включая imageView/accessoriesView)

Когда я устанавливаю UITableViewCells backgroundColor в полупрозрачный цвет, он выглядит хорошо, но цвет не распространяется на всю ячейку.

Площадь вокруг imageView и accessoryView приближается к [UIColor clearColor]...

alt text

Я пробовал явно устанавливать теги cell.accessoryView.backgroundColor и cell.imageView.backgroundColor на тот же цвет, что и ячейка backgroundColor, но она не работает. Он помещает крошечную коробку вокруг значка, но не расширяется, чтобы заполнить левый край. Правый край кажется не затронутым этим.

Как я могу это исправить?

EDIT. Вот код ячейки исходной таблицы:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.opaque = NO;
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4];
        cell.textColor = [UIColor whiteColor];
    }

    cell.imageView.image = [icons objectAtIndex:indexPath.row];
    cell.textLabel.text = [items objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}
4b9b3361

Ответ 1

Сегодня мы с Беном поняли это, вот резюме для группы, если это поймает кого-нибудь еще.

Вы должны установить фон ячейки и cell.textLabel.backgroundColor каждый раз, когда вызывается cellForRowAtIndexPath, а не только во время фазы alloc/init (т.е. если tableView имеет недостаток кэша декомпрессии).

Итак, код станет следующим:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.opaque = NO;        
    }

    // All bgColor configuration moves here
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4];
    cell.textColor = [UIColor whiteColor];
    cell.imageView.image = [icons objectAtIndex:indexPath.row];
    cell.textLabel.text = [items objectAtIndex:indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

Ответ 2

Вы изучили настройку цвета фона ячейки contentView и прозрачность прозрачности ячеек, аксессуаров и изображений?

Кроме того, эта статья может помочь вам показать некоторые альтернативы.