Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UIButton子类,在标题标签上设置NSLayoutConstraint_Swift_Autolayout_Constraints_Subclass - Fatal编程技术网

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
布局子视图中使用时不起作用