Igor
Igor

Reputation: 4207

What is the default TableView section header background color on the iPhone?

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.

Upvotes: 18

Views: 13306

Answers (6)

Rushang Patel
Rushang Patel

Reputation: 90

Hex color - #e8e9ed

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

or you can use #f7f7f7

Upvotes: -1

dobiho
dobiho

Reputation: 1035

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?

Upvotes: -1

Atpl Mohali
Atpl Mohali

Reputation: 138

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)

Upvotes: 4

Darshan Panchal
Darshan Panchal

Reputation: 297

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

}

Upvotes: 5

Rasputin
Rasputin

Reputation: 487

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)

Upvotes: 33

Jbryson
Jbryson

Reputation: 2905

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;

Upvotes: 0

Related Questions