更改 UITableview 中节标题的颜色
-
24-09-2019 - |
题
我有一个非常简单的问题(我希望如此)。如何将 UITableview 中的节标题颜色从默认蓝色更改为黑色透明?提前致谢。
解决方案
您需要在 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,但您可以将其设置为任何您想要的高度。你的问题就是这个意思吗?希望这可以帮助。
其他提示
这是一个老问题,但我认为答案需要更新。
这方法不涉及定义自己的自定义视图。点击 在iOS 6中和了,你可以很容易地通过定义搜索改变背景颜色和文字颜色
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section委托方法。
例如:
- (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/博客/ IOS-如何到定制表 - 视图 - 集管和页脚-颜色/
- (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;
}
不隶属于 StackOverflow