Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:33:56+00:00 2026-05-19T01:33:56+00:00

I am trying to create a table view header with rounded corners but a

  • 0

I am trying to create a table view header with rounded corners but a gap is appearing on the top of the header view and I cannot get rid of it. See picture:
alt text

this is the code I have for the header

#define HEADER_HEIGHT 35.0f


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   return HEADER_HEIGHT;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {


   if (tableView.tableHeaderView) { // header was already created... go away
     return tableView.tableHeaderView;
   }

   CGFloat width = 300.0f;
   CGRect rectArea = CGRectMake(10.0f, 5.0f, width, HEADER_HEIGHT);

   tableView.tableHeaderView = [[[UIView alloc] initWithFrame:rectArea] autorelease];

   UIColor *orange =  [UIColor colorWithRed:(255.0f/255.0f) green:(228.0f/255.0f) blue:0.0f alpha:1.0f];

   [tableView.tableHeaderView setBackgroundColor:orange];

   rectArea = CGRectMake(10.0f, 5.0f, width, HEADER_HEIGHT);
   UILabel *lbl = [[UILabel alloc] initWithFrame:rectArea];
   lbl.text = NSLocalizedString(@"TGERAL", @"");
   lbl.textAlignment = UITextAlignmentLeft;
   lbl.font = [UIFont systemFontOfSize:13.0f];
   lbl.textColor = [UIColor blackColor];
   lbl.backgroundColor = [UIColor clearColor];
   lbl.numberOfLines = 2.0f;
   lbl.lineBreakMode = UILineBreakModeWordWrap;
   //[lbl sizeToFit];

   [tableView.tableHeaderView addSubview:lbl];
   [lbl release];

   self.tableView.tableHeaderView.layer.cornerRadius = 6.0f;

   return tableView.tableHeaderView;
}

If I change HEADER_HEIGHT or I add a certain amount of pixels to the height of the tableHeaderView or to the label height, all that happens is an increase in the gap.

Do you guys know what I am missing?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:33:57+00:00Added an answer on May 19, 2026 at 1:33 am

    A tableview has two types of headers, and I think you’re confusing / intertwining the two.

    The first is the table header. The second is table section headers.

    I’m unclear which one you want. If you want a single header for the whole table, you want the table header, and you set it using tableView.tableHeaderView = myHeaderView. You can set the height of this header by setting the frame height for your view. The tableView will set the width of this header automatically.

    If you want individual headers in each table section, you must override tableView:viewForHeaderInSection:, and return a custom view. Again, you should set the initial frame for this view to the height you want; the tableview will adjust the width.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to create a transparent table view recently but I'm not having
I'm trying to create table from view from remote server (calling procedure UPDATE_PROC), like
I am trying to create a settings table view for my app. I am
I am trying to create a pivot table type view in postgresql and am
I am trying to decide whether to create a global view table or 1
I am trying to add a UISearchbar to table header view. I have the
I am trying to create 3 table view cells using code (w/o nib). I
I'm trying to create a custom table view cell that has a button on
I am trying to create a multi-view app with navigation template. I want table
I am trying to create a table view which uses two types of cells

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.