【发布时间】:2014-06-11 23:10:03
【问题描述】:
viewForHeaderInSection 的 textLabel 的 textColor 始终为灰色。 BackgroundColor 按预期更改。以下是创建 headerview 的代码。它确实进入“!headerView”条件。使用 ios SDK 7.1
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *headerIdentifier = @"InspectionQuestionHeader";
UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerIdentifier];
if (!headerView) {
headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:headerIdentifier];
headerView.contentView.backgroundColor = [UIColor grayColor];
// Why doesn't this work?
headerView.textLabel.textColor = [UIColor whiteColor];
}
InspectionQuestionSection *questionSection = _questionSections[section];
NSString *title = [NSString stringWithFormat:@"%@. %@", questionSection.sectionNumber, questionSection.sectionDescription];
headerView.textLabel.text = title;
return headerView;
}
【问题讨论】:
-
您是在某处为
UILabel设置默认外观颜色,还是在控制器中的任何位置更改标题文本的颜色?因为你的代码对我来说很好(我只替换了标题上的文本) -
在this page 上,tableView:willDisplayHeaderView:forSection: 中的颜色发生变化:
-
啊-您必须使用分组样式表视图。
-
无默认外观;控制器不会对标题或标签做任何事情,尽管我也怀疑这些方面的事情。我尝试在 headerView.contentView 中添加一个 uilabel ,我可以让它变成白色。我会再挖掘一些以确保没有默认值或恶意活动。
标签: ios objective-c uitableview textlabel