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

Как настроить вид таблицы TableView - iPhone

Я знаю, как настроить tableViewCell.

Я видел множество приложений, настраивающих CellView Cell.

Аналогично, я хочу настроить заголовок секции TableView

"Предположим - имя раздела должно быть разным шрифтом, оно имеет разные фоновые изображения и т.д."

Возможно ли это?

В каком методе должен ли я реализовать код?

4b9b3361

Ответ 1

Вместо обычного метода

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

Вы хотите реализовать это:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

Как вы можете видеть, второй возвращает UIView вместо строки для текста. Поэтому вы можете настроить свой собственный вид (с ярлыками и т.д.) И вернуть его.

Вот пример того, как вы можете это сделать (чтобы реализовать этот метод):

// create the parent view that will hold header Label
UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] autorelease];

// create image object
UIImage *myImage = [UIImage imageNamed:@"someimage.png"];;

// create the label objects
UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.font = [UIFont boldSystemFontOfSize:18];
headerLabel.frame = CGRectMake(70,18,200,20);
headerLabel.text =  @"Some Text";
headerLabel.textColor = [UIColor redColor];

UILabel *detailLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
detailLabel.backgroundColor = [UIColor clearColor];
detailLabel.textColor = [UIColor darkGrayColor];
detailLabel.text = @"Some detail text";
detailLabel.font = [UIFont systemFontOfSize:12];
detailLabel.frame = CGRectMake(70,33,230,25);

// create the imageView with the image in it
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,50,50);

[customView addSubview:imageView];
[customView addSubview:headerLabel];
[customView addSubview:detailLabel];

return customView;

Надеюсь, что поможет