希望实现:
分割线,要么左边顶格对齐,要么距离右边有个填充距离
之前设置过separatorInset的left为0,但是不起效果
swift uitableview cell separator left inset
objective c – iOS 8 UITableView separator inset 0 not working – Stack Overflow
看了下说明:
extension UIView { /* -layoutMargins returns a set of insets from the edge of the view’s bounds that denote a default spacing for laying out content. If preservesSuperviewLayoutMargins is YES, margins cascade down the view tree, adjusting for geometry offsets, so that setting the left value of layoutMargins on a superview will affect the left value of layoutMargins for subviews positioned close to the left edge of their superview’s bounds If your view subclass uses layoutMargins in its layout or drawing, override -layoutMarginsDidChange in order to refresh your view if the margins change. */ @available(iOS 8.0, *) public var layoutMargins: UIEdgeInsets |
去设置:
//make separator left align to edge self.tableView.separatorInset = UIEdgeInsetsZero self.tableView.layoutMargins = UIEdgeInsetsZero |
效果:
没变化。
再去试试:
//make separator left align to edge self.tableView.separatorInset = UIEdgeInsetsZero self.tableView.layoutMargins = UIEdgeInsetsZero self.tableView.preservesSuperviewLayoutMargins = true |
效果:
没变化。
结果:
//make separator left align to edge cell.layoutMargins = UIEdgeInsetsZero // cell.layoutMargins.left = 0 cell.preservesSuperviewLayoutMargins = false |
也没变化。
最后用:
//make separator left align to edge cell.separatorInset = UIEdgeInsetsZero cell.layoutMargins.left = 0 cell.preservesSuperviewLayoutMargins = false |
或:
//make separator left align to edge cell.separatorInset = UIEdgeInsetsZero cell.layoutMargins = UIEdgeInsetsZero cell.preservesSuperviewLayoutMargins = false |
都达到了效果:
分隔符完全左右顶格显示了: