How do I add an extra separator to the top of a UITableView?

后端 未结 8 2129
面向向阳花
面向向阳花 2021-02-06 22:20

I have a view for the iPhone that is basically split in two, with an informational display in the top half, and a UITableView for selecting actions in the bottom half. The prob

8条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-06 22:32

    In complement of Ortwin's answer, if you need to add some margin to your top separator to fit the separator inset, you have to embedded your top separator in another view :

    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1 / UIScreen.mainScreen.scale)];
    UIView *topSeparator = [[UIView alloc] initWithFrame:CGRectMake(self.tableView.separatorInset.left, 0, self.tableView.frame.size.width - self.tableView.separatorInset.left - self.tableView.separatorInset.right, 1 / UIScreen.mainScreen.scale)];
    topSeparator.backgroundColor = self.tableView.separatorColor;
    [headerView addSubview:topSeparator];
    self.tableView.tableHeaderView = headerView;
    

    Hope it helps.

提交回复
热议问题