How to determine margin of a grouped UITableView (or better, how to set it)?

前端 未结 9 2432
暗喜
暗喜 2020-12-07 17:48

The grouped UITableView places a margin between the edge of the view and the table cells. Annoyingly (for me) this margin is some function of the width of the view.

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 18:42

    I would like to supplement Matthew's answer with a code to set-up fixed margin.

    1. Subclass UITableViewCell.
    2. Implement setFrame:
    - (void)setFrame:(CGRect)frame
    {
        CGFloat inset = 15.0;
        CGFloat tableWidth = 400.0;
        frame.origin.x -= [self groupedCellMarginWithTableWidth:tableWidth] - inset;
        frame.size.width = frame.size.width + 2 * ([self groupedCellMarginWithTableWidth:tableWidth] - inset);
        [super setFrame:frame];
    }
    

    This will set left and right margin for 15.0 while table width may vary.

提交回复
热议问题