【问题标题】:iOS 7 - viewForHeaderInSection textlabel always grayiOS 7 - viewForHeaderInSection 文本标签总是灰色
【发布时间】: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


【解决方案1】:

这是您想要放入不同委托方法的内容。 试试这个:

-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
UITableViewHeaderFooterView *headerIndexText = (UITableViewHeaderFooterView *)view;
[headerIndexText.textLabel setTextColor:[UIColor whiteColor]];
}

【讨论】:

    猜你喜欢
    • 2014-03-16
    • 2015-02-20
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 2013-09-18
    • 2013-09-27
    • 2013-09-26
    • 1970-01-01
    相关资源
    最近更新 更多