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

前端 未结 9 2403
暗喜
暗喜 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:30

    By creating (and using!) a subclass of UITableViewCell, you can possibly achieve what you're looking for. Just move the contentview and backgroundview around in layoutsubviews, as in the code sample below which shifts the visible parts of the cell 20pt to the right.

    - (void) layoutSubviews
    {
        NSLog (@"Cell/contentview/backgroundview before:\n%@\n%@\n%@", self, self.contentView, self.backgroundView);
        [super layoutSubviews];
        CGRect frame = self.backgroundView.frame;
        frame.origin.x += 20;
        frame.size.width -= 20;
        self.backgroundView.frame = frame;
        frame = self.contentView.frame;
        frame.origin.x += 20;
        frame.size.width -= 20;
        self.contentView.frame = frame;
    
        NSLog (@"Cell/contentview/backgroundview after:\n%@\n%@\n%@", self, self.contentView, self.backgroundView);
    }
    

提交回复
热议问题