The default height is too large for me. How can I change the height between two sections?
============================================================================
Sorry for my poor English... I mean the gap between two sections is too large. How to change it?
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CGRect frame = CGRectMake(0, 0, tableView.frame.size.width, 2.0f);
UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease];
view.backgroundColor = [UIColor blueColor];
return view;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
CGRect frame = CGRectMake(0, 0, tableView.frame.size.width, 2.0f);
UIView *view = [[[UIView alloc] initWithFrame:frame] autorelease];
view.backgroundColor = [UIColor redColor];
return view;
}
I changed the header view and footer view of each section. And here is the result:
I think there may be a min height of the gap, because I set the height of header and footer to 2px, but the gap between two sections is still so large.
You could use footer views between each of your sections and give them the size of the space you desire by implementing the following methods in your UITableView's delegate.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
In the first delegate method you can return a simple UIView instance, and in the second you can return the height that this view should be. This second delegate method should allow you to control the gap between sections.
On iOS 15 you can change the section header top padding
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With