ios - UITableViewCell contentView 中的自动布局

标签 ios swift autolayout uikit constraints

我正在尝试以编程方式创建约束,以将这个粉红色的 UIView 置于 UITableViewCell 的中心。但是,当我添加约束时,它们不适用,并且我在控制台中收到一条消息,指出某些 NSAutoresizingMaskLayoutConstraints 不能同时满足。

因此,当我设置 cell.contentView.translatesAutoresizingMaskIntoConstraints = false 时,我在控制台中收到此消息:

"Changing the translatesAutoresizingMaskIntoConstraints property of the contentView of a UITableViewCell is not supported and will result in undefined behavior, as this property is managed by the owning UITableViewCell".

View 确实居中,但控制台显示我不应该更改此属性。

我怎样才能做到这一点?

Before setting the property to false

After setting the property to false

非常感谢。

最佳答案

此外,请确保在您的单元格的 xib 中,应选择 Layout 以

“自动调整蒙版”

而不是“推断(自动调整掩码)”

如图所示

enter image description here

关于ios - UITableViewCell contentView 中的自动布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51021203/

相关文章:

ios - AFJSONRequestSerializer 和 AFHTTPRequestSerializer 之间的区别

ios - 具有可变宽度但限制在父级内的按钮 - iOS 自动布局

ios - 为什么 UILayoutGuide 在 subviews 数组中的顺序不一致?

ios - 架构 x86_64 flutter 的 undefined symbol

ios - iOS 设备上的 OpenSSL 压缩

ios - 使用委托(delegate)将数据从模态视图传递到父 View (在 Storyboard中使用 segue)

ios - 快速访问不同 View Controller 之间的 UI 属性

ios - 关于 Analytics 屏幕报告的 Firebase Analytics 错误

ios - 复选标记不会打开/关闭

ios - Interface Builder 中的 "Width equals height"约束