Ios 如何在Xcode中以编程方式配置约束?
我有一个UIViewController上的UIButton,名为Home。确切地说,我不确定我应该在项目中键入什么:。我在这里浏览了一遍,但找不到我要找的东西Ios 如何在Xcode中以编程方式配置约束?,ios,autolayout,constraints,Ios,Autolayout,Constraints,我有一个UIViewController上的UIButton,名为Home。确切地说,我不确定我应该在项目中键入什么:。我在这里浏览了一遍,但找不到我要找的东西 var bottomSpaceUpgradeButtonNSLayoutConstraint = NSLayoutConstraint( item: buttonUpgrade, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toIt
var bottomSpaceUpgradeButtonNSLayoutConstraint = NSLayoutConstraint(
item: buttonUpgrade,
attribute: NSLayoutAttribute.Bottom,
relatedBy: NSLayoutRelation.Equal,
toItem: buttonUpgrade(Home).Bottom,
attribute: NSLayoutAttribute.Bottom,
multiplier: 1,
constant: -460);
这就是我试图复制的约束:
我不是100%确定你想做什么,因为你没有告诉我们你想如何定位家,但我会试试这个:
var bottomSpaceUpgradeButtonNSLayoutConstraint = NSLayoutConstraint(
item: buttonUpgrade,
attribute: NSLayoutAttribute.Top,
relatedBy: NSLayoutRelation.Equal,
toItem: self.view,
attribute: NSLayoutAttribute.Bottom,
multiplier: 1,
constant: -460);
Home是一个UIViewController。我想把按钮放在它的最底部,这样它就看不见了。谢谢你的回答,我会很快查出来。谢谢你更新你的答案。我使用您的代码得到此错误:。你能看看这张照片吗?谢谢您看到的错误表明UIViewController的实例未被称为Home。谢谢。我应该在代码中的某个地方声明UIViewController吗?实际上我还没有申报。我反复检查,我的故事板UIViewController被称为Home。谢谢我会建议你使用Swift和Objective-C,虽然我可以混合使用Swift和Objective-C,但这不是有点复杂吗?Snap呢?看起来很不错。但是,这次我只需要修改约束,这样就不适合我了。如果我不能解决我的问题,我会用它。谢谢你的建议!