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

发布于 2024-12-25 01:41:10 字数 263 浏览 3 评论 0原文

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

[UIColor colorWithHue:0.6 饱和度:0.33 亮度:0.69 alpha:0.6]。

但我手动找到了这些值。

I want to customize TableView section header and to leave default background color. I use - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section. I need to change font size depending on device (iPad or iPhone). For this purpose call next function:

[UIColor colorWithHue:0.6 saturation:0.33 brightness: 0.69 alpha:0.6].

But I found these values manually.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

满身野味 2025-01-01 01:41:10

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)

The default tableview section header background color for ios7 is

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)
北方。的韩爷 2025-01-01 01:41:10

对于仅一行内容更改 TableView 标题部分的背景颜色
添加 TableView 委托 willDisplayHeaderView

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

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

}

For Change background Color of TableView Header Section Just One Line stuff
add TableView delegate willDisplayHeaderView:

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

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

}
羞稚 2025-01-01 01:41:10

Objective-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)

Objective-C:

[UIColor colorWithRed:232/255.0f green:233/255.0f blue:237/255.0f alpha:1.0f]

Swift:

UIColor(red: 232/255, green: 233/255, blue: 237/255, alpha: 1)
旧人九事 2025-01-01 01:41:10

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

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 作为约束宽度,以在任一侧提供标签边框。然后我使用了这样的可拉伸图像:

UITableViewHeaderImage

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

    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;

What I've done in one of my apps is to create the text like so:

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);

I used 290 for the constraint width to give the label boarders on either side. I then used a stretchable image like this:

UITableViewHeaderImage

And scaled it to fit the text in the header:

    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];

Finally, I created a label and added it as a subview:

    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;
反差帅 2025-01-01 01:41:10

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

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

    对象

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

但是,每当苹果改变颜色时我们就需要改变。

如何获得默认的节标题颜色?

for iOS 11, I picked it's color on simulator.

  • object c: [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1.0]

  • swift : UIColor(red: 247/255.0, green: 247/255.0, blue: 247/255.0, alpha: 1.0)

But, we need to change whenever Apple changed the color.

How to get default section header color?

青柠芒果 2025-01-01 01:41:10

十六进制颜色 - #e8e9ed

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

或者你可以使用 #f7f7f7

Hex color - #e8e9ed

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

or you can use #f7f7f7

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文