У меня довольно простой простой вопрос (надеюсь). Как изменить цвет заголовка раздела в UITableview с синего по умолчанию на черный прозрачный? Заранее спасибо.
Изменение цвета заголовка раздела в UITableview
Ответы (2)
вам необходимо реализовать этот метод в протоколе UITableViewDelegate:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Вот ссылка на документация
... и сделайте что-то вроде этого (подпункт вашего собственного цвета):
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[sectionView setBackgroundColor:[UIColor blackColor]];
return sectionView;
Вы также можете использовать целое число раздела для чередования цветов или чего-то подобного. Я думаю, что высота секций по умолчанию - 22, но вы можете сделать все, что захотите. Это то, что вы имели в виду под своим вопросом? Надеюсь это поможет.
Это старый вопрос, но я думаю, что ответ нужно обновить.
This method does not involve defining your own custom views.
In iOS 6 and up, you can easily change the background color and the text color by defining the
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)sectiondelegate method.
Например:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { // Background color view.tintColor = [UIColor blackColor]; // Text Color UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; [header.textLabel setTextColor:[UIColor whiteColor]]; // Another way to set the background color // Note: does not preserve gradient effect of original header // header.contentView.backgroundColor = [UIColor blackColor]; }
Взято из моего сообщения здесь: https://happyteamlabs.com/blog/ios-how-to-customize-table-view-header-and-footer-colors/