Добавление изображения рядом с заголовком заголовка в UITableView - PullRequest
0 голосов
/ 21 февраля 2012

Я создал UITableView, используя стиль группы. У меня в таблице только одна группа.

Вот мои два вопроса:

1) Как отобразить картинку рядом с моим заголовком в верхнем заголовке? В основном я хотел бы разместить логотип нашей компании рядом с этим названием.

2) Могу ли я изменить цвет фона (мне не нравится серый) в заголовке и можно ли отрегулировать высоту этого заголовка?

1 Ответ

0 голосов
/ 22 февраля 2012

Просто верните пользовательский вид в ваш заголовок следующим образом:

    //Draws a custom view for the header instructions
-(UIView*)tableView:(UITableView*) tableView viewForHeaderInSection:(NSInteger)section;
{
    if ([tableView numberOfRowsInSection:section] != 0) // To handle nil entries
    {
    UIView* headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 60)] autorelease];

         // set up whatever view you want here. E.g.

    UILabel* headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, headerView.frame.size.width - 20.0, headerView.frame.size.height)];

        headerLabel.text = @"Tap items in the list to pin them.\nTap the Remix button to clear all unpinned items";
        headerLabel.numberOfLines = 0;

    headerLabel.font = [UIFont fontWithName:@"HelveticaNeueLTStd-Lt" size: 14];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.textColor = [UIColor colorWithRed:kColorRed green:kColorGreen blue:kColorBlue alpha:1];
    headerLabel.userInteractionEnabled = NO;
        headerLabel.textAlignment = UITextAlignmentCenter;

    headerView.backgroundColor = [UIColor clearColor];

    [headerView setTag:010];
    [headerView setAlpha:1];

    [headerView addSubview:headerLabel];
    [headerLabel release];
    return headerView;
    }
    else {
        return nil;    // again to handle nil tables. You should be nice and at least show an error label on the view.
    }    
}

И это даст вам что-то вроде этого:

How it should only work

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