How to decrease spacing between cell title and cell text in UITableView

Is it possible to decrease the spacing between cell title and cell text? After looking at the example below, I would like the heading to be closer to the top of a cell that contains other text.

Sorry, I don't have a high enough reputation for pasting images.

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

+2


a source to share


3 answers


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



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

      

+3


a source


I am assuming you are using standard cell style and textLabel. You can change the frame.origin of the label, or create a custom cell from the nib with the exact position you prefer.



0


a source


You need to use a method heightForHeaderInSection

to define the space between the title and the text of the cell. You can also change it depending on different sections, for example. in some sections you may need more spacing, and under some, you may not want to show the space. In such a case, you can use CGFLOAT_MIN, which is 0.000001f. By giving an example how you can use a different section with different heading heights

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

      

Hope this helps you.

0


a source







All Articles