I'm developing for iPad, and when I try to constraint to the right of the table view cell, it gets constrained to the right of the screen, and not constrained to the line separator edge.
declineButton?.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
declineButton?.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -10).isActive = true
declineButton?.heightAnchor.constraint(equalToConstant: 18).isActive = true
declineButton?.widthAnchor.constraint(equalToConstant: 18).isActive = true
The code above just constrains it to the far right.
Example: Notice how the "Followed" button on the right is constrained to the edge of the separator.
The separator
of the UITableViewCell
isn't exposed in such a way that you can constrain things to it. You might be able to search through the cell's view hierarchy, but you're better off setting your table's separatorStyle
to none
, and adding your own UIView
separator, which you can then customize and constrain other subviews to. Considering the separator in your image example doesn't look like stock to me, I'd guess that is what they did too.
Edit: another solution I just considered, if you really want to keep the stock separator:
The difference between the right edge of the separator and the right edge of the cell can be defined like this (Swift 3):
let rightConstant = myTable.layoutMargins.right + myTable.separatorInset.right + myCell.layoutMargins.right
Use this as your constant for the right constraint.