如何在自定义单元格上使用带有附件视图的`readableContentGuide`?

问题描述 投票:3回答:1

我创建了UITableViewCell的自定义子类。我想将子视图的边缘与readableContentGuide锚点对齐:

let guide = contentView.readableContentGuide
myView.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true

enter image description here

这可以正常工作,直到我添加一个附件视图,这会导致布局关闭。

accessoryType = .discloseIndicator

enter image description here

在默认单元格上,布局正常工作:

enter image description here

我很想知道这是一个UIKit错误还是我应该采用不同的方式呢?

我提出了一个临时解决方法,我将我的子视图附加到默认文本标签,这似乎有效,但我当然不愿意。

textLabel?.text = " "
myView.leadingAnchor.constraint(equalTo: textLabel!.leadingAnchor).isActive = true

enter image description here

ps:蓝色框显示cell.contentView的框架(通过View调试器)

ios autolayout tableviewcell
1个回答
0
投票
  1. 在表视图上将cellLayoutMarginsFollowReadableWidth设置为true
tableView.cellLayoutMarginsFollowReadableWidth = true
  1. 或者,您可以在Interface Builder中的表视图上选中Follow Readable Width
© www.soinside.com 2019 - 2024. All rights reserved.