Uitableview iPhone上默认的TableView节标题背景颜色是什么?

Uitableview iPhone上默认的TableView节标题背景颜色是什么?,uitableview,tableview,Uitableview,Tableview,我想自定义TableView节标题并保留默认背景色。我使用-(UIView*)tableView:(UITableView*)tableView视图用于headerinsection:(NSInteger)节。我需要根据设备(iPad或iPhone)更改字体大小。为此,调用下一个函数: [UIColor colorWith色调:0.6饱和度:0.33亮度:0.69 alpha:0.6] 但是我手动找到了这些值 我在我的一个应用程序中所做的就是创建如下文本: NSString *sectionTi

我想自定义TableView节标题并保留默认背景色。我使用-
(UIView*)tableView:(UITableView*)tableView视图用于headerinsection:(NSInteger)
节。我需要根据设备(iPad或iPhone)更改字体大小。为此,调用下一个函数:

[UIColor colorWith色调:0.6饱和度:0.33亮度:0.69 alpha:0.6]


但是我手动找到了这些值

我在我的一个应用程序中所做的就是创建如下文本:

NSString *sectionTitle = @"YOUR TITLE HERE";
CGSize sz = [sectionTitle  sizeWithFont:[UIFont boldSystemFontOfSize:20.0f] 
                   constrainedToSize:CGSizeMake(290.0f, 20000.0f)
                       lineBreakMode:UILineBreakModeWordWrap];

CGFloat height = MAX(sz.height, 20.0f);

CGRect sectionFrame = CGRectMake(0.0, 0.0, 320.0, height);
我使用290作为约束宽度,以给出两侧的标签边界。然后,我使用了如下可拉伸图像:

并将其缩放以适合标题中的文本:

    UIImage *headerImage = [UIImage imageNamed:@"sectionheaderbackground.png"];
    UIImage *stretchableImage = [headerImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:sectionFrame];
    backgroundImageView.image = stretchableImage;

    // Add it to the view for the header
    UIView *sectionView = [[UIView alloc] initWithFrame:sectionFrame];
    sectionView.alpha = 0.9; 
    sectionView.backgroundColor = [UIColor clearColor];
    [sectionView addSubview:backgroundImageView];
最后,我创建了一个标签并将其添加为子视图:

    CGRect labelFrame = CGRectMake(10.0, 0.0, 290.0, height);
    UILabel *sectionLabel = [[UILabel alloc] initWithFrame:labelFrame];
    sectionLabel.text = sectionTitle;
    sectionLabel.numberOfLines = 0;
    sectionLabel.font = [UIFont boldSystemFontOfSize:18.0];
    sectionLabel.textColor = [UIColor whiteColor];
    sectionLabel.shadowColor = [UIColor grayColor];
    sectionLabel.shadowOffset = CGSizeMake(0, 1);
    sectionLabel.backgroundColor = [UIColor clearColor];
    [sectionView addSubview:sectionLabel];

    return sectionView;

ios7的默认tableview节标题背景颜色为

Objective-C
[UIColor colorWithRed:247/255.0f green:247/255.0f blue:247/255.0f alpha:1.0f]

Swift
UIColor(red: 247/255, green: 247/255, blue: 247/255, alpha: 1)

要更改TableView标题部分的背景色,只需一行内容 添加
TableView
delegate
willDisplayHeaderView

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {

   UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
   **header.tintColor = [UIColor whiteColor];**

}
目标C:

[UIColor colorWithRed:232/255.0f green:233/255.0f blue:237/255.0f alpha:1.0f]
斯威夫特:

UIColor(red: 232/255, green: 233/255, blue: 237/255, alpha: 1)

对于iOS 11,我在模拟器上选择了它的颜色

  • 对象c:[UIColor COLOR WITH RED:247/255.0绿色:247/255.0蓝色:247/255.0 alpha:1.0]

  • swift:UIColor(红色:247/255.0,绿色:247/255.0,蓝色:247/255.0,alpha:1.0)

但是,只要苹果改变颜色,我们就需要改变

如何获取默认节标题颜色?

十六进制颜色-#e8e9ed

RGB颜色-UIColor(红色:232/255,绿色:233/255,蓝色:237/255,alpha:1)


或者你可以使用#f7f7f7

因为所有的颜色成分都是相同的(247/255),一个更简单的选择是:
UIColor(白色:0.97,alpha:1)
其中0.97~247/255我希望这个答案能在iOS13和暗模式下更新。我们是否可以使用标准UIColor来代替那些硬编码的值?这适用于iOS 9和laterRGB颜色:#e8e9ed