我有一个非常简单的问题(我希望如此)。如何将UITableview中的部分标题颜色从默认蓝色更改为黑色透明? 在此先感谢。在UITableview中更改节标题的颜色
9
A
回答
18
需要实现在的UITableViewDelegate协议这种方法:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
这里是到documentation
链接...和做这样的事情(Sub在自己的颜色):
UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[sectionView setBackgroundColor:[UIColor blackColor]];
return sectionView;
您也可以使用整数部分替代颜色或类似的东西。我认为这些部分的默认高度是22,但您可以随心所欲地制作它。这是你的问题的意思吗?希望这可以帮助。
0
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,tableView.bounds.size.width, 30)];
if (section == 0)
[headerView setBackgroundColor:[UIColor redColor]];
else
[headerView setBackgroundColor:[UIColor clearColor]];
return headerView;
}
20
这是一个老问题,但我认为答案需要更新。
此方法不涉及定义您自己的自定义视图。
在iOS 6及更高版本中,您可以通过定义代理方法来轻松更改背景颜色和文本颜色。
例如:
- (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/
这是一个类似的问题:http://stackoverflow.com/questions/813068/uitableview-change-section-header -color – nylund 2011-12-01 13:46:39