I created a custom subclass of UITableViewCell
. I want to align the edges of my subview to the readableContentGuide
anchors:
let guide = contentView.readableContentGuide
myView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
This works as expected until I add an accessory view, which causes the layout to be off.
accessoryType = .discloseIndicator
On the default cells the layout works correctly:
I'm curious to know if this is a UIKit bug or if there's a different way I should be doing this?
I came up with a temporary workaround where I attach my subview to the default text label, which seems to work but of course I'd rather not.
textLabel?.text = " "
myView.leadingAnchor.constraint(equalTo: textLabel!.leadingAnchor).isActive = true
ps: the blue box shows the frame of the cell.contentView
(via the View debugger)
cellLayoutMarginsFollowReadableWidth
to true
on Table View tableView.cellLayoutMarginsFollowReadableWidth = true
Follow Readable Width
on Table View in the Interface Builder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.