gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 08:13:44 26 4
gpt4 key购买 nike

概览

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

  • 静态单元格(内容不是动态填充的)
  • 样式分组

问题

  1. 如何更改静态 TableView 的节标题的文本颜色?

最佳答案

您需要创建自己的标题 View :

在您的 TableView 数据源/委托(delegate)中实现

- (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;
}

关于iOS - 表格 View - 静态单元格(分组) - 更改节标题文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10232368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com