简体   繁体   中英

How to use `readableContentGuide` with accessory view on a custom cell?

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)

  1. Set cellLayoutMarginsFollowReadableWidth to true on Table View
tableView.cellLayoutMarginsFollowReadableWidth = true
  1. Alternatively you can checkmark 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM