How to change height of grouped UITableView header?

I know how to change the height of section headers in a table view. But I can not find a solution to change the default interval before the first sector.

I now have this code:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section == 0){ return 0; } return 10; } 

enter image description here

+54
ios uikit uitableview tableview
Jul 17 '13 at 12:31 on
source share
8 answers

It looks like I cannot set the table header view to a height of 0. I ended up doing the following:

 - (void)viewWillAppear:(BOOL)animated{ CGRect frame = self.tableView.tableHeaderView.frame; frame.size.height = 1; UIView *headerView = [[UIView alloc] initWithFrame:frame]; [self.tableView setTableHeaderView:headerView]; } 
+13
Jul 17 '13 at 12:43 on
source share

Return CGFLOAT_MIN instead of 0 for the desired section height.

Returning 0 causes the UITableView to use the default value. This is undocumented behavior. If you return a very small number, you will effectively get a header with zero height.

Swift 3:

  func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { if section == 0 { return CGFloat.leastNormalMagnitude } return tableView.sectionHeaderHeight } 

Swift:

 func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { if section == 0 { return CGFloat.min } return tableView.sectionHeaderHeight } 

Obj-C:

  - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0) return CGFLOAT_MIN; return tableView.sectionHeaderHeight; } 
+176
May 30 '14 at
source share

You can try the following:

In loadView

 _tableView.sectionHeaderHeight = 0; 

Then

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

It should be deleted until you have the objects in the header ...

And if you need some kind of partition size, then change only the return value.

the same if you did not delete the sequencer.

 _tableView.sectionFooterHeight = 0; 

and

 -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0; } 

Well, this works for my table view problems in iOS7.

+13
Oct 03 '13 at 11:53 on
source share

If you use a tableView style grouped , tableView automatically sets the top and bottom inserts. To avoid them and avoid installing internal attachments, use the delegate methods for the header and footer. Never return 0.0, but CGFLOAT_MIN .

Objective-c

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { // Removes extra padding in Grouped style return CGFLOAT_MIN; } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { // Removes extra padding in Grouped style return CGFLOAT_MIN; } 

Swift

 func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { // Removes extra padding in Grouped style return CGFloat.leastNormalMagnitude } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { // Removes extra padding in Grouped style return CGFloat.leastNormalMagnitude } 
+10
Jun 23 '16 at 15:49
source share

In swift 2.0

 func tableView(tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat { return yourHeight } 
+2
Sep 02 '15 at 10:56
source share

you can use viewForHeaderInSection and return the view with any height.

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { int height = 30 //you can change the height if(section==0) { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, height)]; return view; } } 
+1
Jul 17 '13 at 13:03 on
source share

You must remove the code self.tableView.tableHeaderView = [UIView new]; after adding

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return CGFLOAT_MIN; }

+1
Nov 23 '15 at 11:23
source share

ViewForHeaderInSection example:

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 118)]; view.backgroundColor = COLOR_DEFAULT; NSString* key = [self.tableKeys objectAtIndex:section]; NSArray *result = (NSArray*)[self.filteredTableData objectForKey:key]; SZTicketsResult *ticketResult = [result objectAtIndex:0]; UIView *smallColoredView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, 320, 3)]; smallColoredView.backgroundColor = COLOR_DEFAULT_KOSTKY; [view addSubview:smallColoredView]; UIView *topBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 8, 320, 40)]; topBackgroundView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:248.0/255.0 blue:174.0/255.0 alpha:1]; [view addSubview:topBackgroundView]; UILabel *totalWinnings = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 300, 40)]; totalWinnings.text = ticketResult.message; totalWinnings.minimumFontSize = 10.0f; totalWinnings.numberOfLines = 0; totalWinnings.backgroundColor = [UIColor clearColor]; totalWinnings.font = [UIFont boldSystemFontOfSize:15.0f]; [view addSubview:totalWinnings]; UIView *bottomBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 55, 320, 58)]; bottomBackgroundView.backgroundColor = [UIColor colorWithRed:255.0/255.0 green:248.0/255.0 blue:174.0/255.0 alpha:1]; [view addSubview:bottomBackgroundView]; UILabel *numberOfDraw = [[UILabel alloc] initWithFrame:CGRectMake(10, 55, 290, 58)]; numberOfDraw.text = [NSString stringWithFormat:@"sometext %@",[ticketResult.title lowercaseString]];; numberOfDraw.minimumFontSize = 10.0f; numberOfDraw.numberOfLines = 0; numberOfDraw.backgroundColor = [UIColor clearColor]; numberOfDraw.font = [UIFont boldSystemFontOfSize:15.0f]; [view addSubview:numberOfDraw]; return view; 
0
Jul 17 '13 at 13:40
source share



All Articles