首页 > 解决方案 > 编程约束切断了我的标签底部

问题描述

我有一个带有根UITableViewCell和子的 Nib 文件UILabel,我在运行时使用编程约束锚定它

        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 个垂直填充的同时摆脱剪裁?

标签: iosswiftxcodeuilabelnslayoutconstraint

解决方案


将图像标签底部锚点从equalTo 更改lessThanOrEqualTo

lblAccountItemTitle.bottomAnchor.constraint(lessThanOrEqualTo: self.bottomAnchor, constant: -16).isActive = true

推荐阅读