Swift UIButton子类,在标题标签上设置NSLayoutConstraint
因此,我创建了一个Swift UIButton子类,在标题标签上设置NSLayoutConstraint,swift,autolayout,constraints,subclass,Swift,Autolayout,Constraints,Subclass,因此,我创建了一个UIButton子类,在这个子类中,我想设置一个新的自动布局约束,如下所示: self.addConstraint(NSLayoutConstraint(item: self.titleLabel, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: -2)) 显然,在UIButton类中,已经有一个约束将UIButton的ce
UIButton
子类,在这个子类中,我想设置一个新的自动布局约束,如下所示:
self.addConstraint(NSLayoutConstraint(item: self.titleLabel, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: -2))
显然,在UIButton
类中,已经有一个约束将UIButton
的centerY
设置为等于标题标签的centerY
。因此,我有相互冲突的约束
是否有一种方法来无效设置在<代码> UIButton < /代码>类中的约束或修改它?< /p>你能解释一下为什么要尝试这个吗,你已经有了属性来设置标题边缘插入<代码> StItTeLeEdEGESETSUSE/COD>实际上,我没有考虑,但是这个函数似乎特别是为此创建的。谢谢如果必须使用
removeConstraint(self.titleLabel)
,但更好的方法是setTitleEdgeInsets
setTitleEdgeInsets
在布局子视图中使用时不起作用