首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >iOS -表格视图-静态单元格(分组)-更改节标题文本颜色

iOS -表格视图-静态单元格(分组)-更改节标题文本颜色
EN

Stack Overflow用户
提问于 2012-04-20 00:17:55
回答 4查看 13.9K关注 0票数 17

概述

我有一个带有表视图的iOS项目,其规范如下:

动态单元格分组(content is not

  • static populated)
  • style is

问题

  1. 如何更改静态表格视图的节标题的文本颜色?
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-04-20 00:53:42

您需要创建自己的header视图:

在表视图数据源/委托中实现

代码语言:javascript
复制
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    // Create label with section title
    UILabel *label = [[[UILabel alloc] init] autorelease];
    label.frame = CGRectMake(20, 6, 300, 30);
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor colorWithHue:(136.0/360.0)  // Slightly bluish green
                                 saturation:1.0
                                 brightness:0.60
                                      alpha:1.0];
    label.shadowColor = [UIColor whiteColor];
    label.shadowOffset = CGSizeMake(0.0, 1.0);
    label.font = [UIFont boldSystemFontOfSize:16];
    label.text = sectionTitle;

    // Create header view and add label as a subview

    // you could also just return the label (instead of making a new view and adding the label as subview. With the view you have more flexibility to make a background color or different paddings
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, SectionHeaderHeight)];
    [view autorelease];
    [view addSubview:label];

    return view;
}
票数 31
EN

Stack Overflow用户

发布于 2013-06-15 22:07:47

也可以做到这点:

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    [[((UITableViewHeaderFooterView*) view) textLabel] setTextColor:[UIColor whiteColor]];
}

.

票数 14
EN

Stack Overflow用户

发布于 2014-06-30 20:37:46

我只能在添加标题的高度和视图之后才能查看标题

代码语言:javascript
复制
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 110;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10232368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档