aahrens
aahrens

Reputation: 5590

How to shrink the spacing between Cell Header and Cell Text in UITableView

Is it possible to shrink the spacing between a cell header and cell text? Looking at the example below I'd like the header to be closer to the top of the cell that contains the other text.

Sorry, I don't have high enough reputation to embed images.

http://www.freeimagehosting.net/uploads/6afdd58c2f.jpg

Upvotes: 2

Views: 499

Answers (3)

Ash
Ash

Reputation: 5712

You need to use method heightForHeaderInSection for defining space between header & cell text. You can also change it depending on different sections for eg. at some sections you may need to show more distance & under some, you don't want to show gap. For such case you can use CGFLOAT_MIN which is 0.000001f. Giving you an example, how you can use different section with different header heights

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0 || section == 2)
    {
        return 55.0;
    }
    else
    {
        return CGFLOAT_MIN;
    }
}

Hope it will help you.

Upvotes: 0

cduhn
cduhn

Reputation: 17918

Just implement tableView:heightForHeaderInSection: in your controller and return your desired height.

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

Upvotes: 3

Paul Lynch
Paul Lynch

Reputation: 19789

I assume that you are using a standard cell style and textLabel. You could change the frame.origin of the label, or create a custom cell from a nib with the exact layout you prefer.

Upvotes: 0

Related Questions