【发布时间】:2020-03-22 04:20:24
【问题描述】:
我有一个带有根 UITableViewCell 和子 UILabel 的 Nib 文件,我在运行时使用编程约束锚定它
lblAccountItemTitle.translatesAutoresizingMaskIntoConstraints = false
lblAccountItemTitle.topAnchor.constraint(lessThanOrEqualTo: self.topAnchor, constant: 16).isActive = true
lblAccountItemTitle.bottomAnchor.constraint(lessThanOrEqualTo: self.bottomAnchor, constant: -16).isActive = true
lblAccountItemTitle.leadingAnchor.constraint(equalTo: imgAccountItemLeft.trailingAnchor, constant: 16).isActive = true
lblAccountItemTitle.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -32).isActive = true
lblAccountItemTitle.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
另外,我注意到我的底部锚点越短,文本被剪裁的越少
如何在保持相等的 16 个垂直填充的同时摆脱剪裁?
【问题讨论】:
-
尝试删除标签的顶部和底部约束,因为它已经对视图的 Y 中心进行了约束。 (或将其更改为图像的 centerY。)。
标签: ios swift xcode uilabel nslayoutconstraint