Reducing the space between sections of the UITable

2019-01-03 12:17发布

Is there a way to reduce the space between two sections of a UITableView? There are about 15 pixels between every single section I have. I did already try to return 0 for -tableView:heightForFooterInSection: and -tableView:heightForHeaderInSection: but that doesn't change anything.

Any suggestions?

9条回答
Viruses.
2楼-- · 2019-01-03 12:43

You can actually set the footer/header/cell heights in Interface Builder under the size tab. By default the header/footer are set at 10.0.

查看更多
相关推荐>>
3楼-- · 2019-01-03 12:44

UPDATE FOR iOS7: Due to ARC autorelease update, here's @Martin Stolz code edited.

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

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

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

(Using iOS7, Xcode v5.0)

查看更多
趁早两清
4楼-- · 2019-01-03 12:49

You can also reduce the height of section footer and header from the storyboard. In the tableview -> size inspector. Go to Section Height.

Size inspector for UITableView in storyboard.

By default it is set to 22 for Plain style table and 10 for grouped style table. You can configure values by increasing / decreasing the values for header and footer separately.

查看更多
戒情不戒烟
5楼-- · 2019-01-03 12:50

For me the issue was because I was using a grouped table view style (UITableViewStyleGrouped). When I changed it to a plain style (UITableViewStylePlain) my tableView:heightForHeaderInSection: method was the only thing determining the size of each section header.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-03 12:52

For me just this issue got resolved just by using the following code,

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return section == 0 ? 1 : 20 // 20 is my other sections height
}

Returning 1 for the first section has solved the issue.

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-01-03 12:55

Use this perhaps, 0 will not work as expected

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

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return .leastNormalMagnitude
}
查看更多
登录 后发表回答