Цвет фона ячейки отображается только до текста - PullRequest
0 голосов
/ 10 февраля 2009

Я зашел так далеко, что использовал следующий код для установки цвета фона ячейки TableView (в cellForRowAtIndexPath)

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

    static NSString *CellIdentifier = @"Cell";

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


        cell.backgroundColor = [UIColor yellowColor];
        cell.contentView.backgroundColor = [UIColor yellowColor];

        UIView* backgroundView = [ [ [ UIView alloc ] initWithFrame:CGRectZero ] autorelease ];
        backgroundView.backgroundColor = [ UIColor yellowColor ];
        cell.backgroundView = backgroundView;
        for ( UIView* view in cell.contentView.subviews ) 
        {
            view.backgroundColor = [ UIColor yellowColor ];
        }
    }

    // Set up the cell...
    if ([[menuList objectAtIndex:indexPath.row] isKindOfClass:[Category  class]])
    {
        cell.text = ((Category *)[menuList objectAtIndex:indexPath.row]).name;
    }
    else
    {
        [cell setText: [menuList objectAtIndex:indexPath.row]];
    }


    return cell;
}

Однако, когда он рендерит только часть ячейки, фон применяется примерно так (где z - заливка bg), даже фоном Аксессуара является цвет, а не текст.

xxxxxxxxxxxxxxxxxxxx
zzzSearch          
xxxxxxxxxxxxxxxxxxxx

Единственный способ изменить фон текста - установить цвет фона для всей таблицы в Интерфейсном Разработчике

Ответы [ 2 ]

0 голосов
/ 11 февраля 2009

Мне удалось сделать это с помощью объекта Custom TableViewCell, но я уверен, что должен быть способ сделать это без

0 голосов
/ 10 февраля 2009

Бьюсь об заклад, ваш текст непрозрачный UILabel. Я помню, что мне пришлось добавить myText.backgroundColor = [UIColor clearColor] к текстовому содержимому UILabel, чтобы заставить его работать правильно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...