这是我正在尝试的代码:
@IBOutlet weak var btnInfo: UIButton!
override func viewWillAppear(_ animated: Bool) {
self.view.addConstraint(NSLayoutConstraint(item: self.view,
attribute: .topMargin,
relatedBy: .equal,
toItem: btnInfo,
attribute: .notAnAttribute,
multiplier: 1,
constant: 20))
self.view.addConstraint(NSLayoutConstraint(item: self.view,
attribute: .rightMargin,
relatedBy: .equal,
toItem: btnInfo,
attribute: .notAnAttribute,
multiplier: 1,
constant: 30))
}
尝试添加 .topMargin
和 .rightMargin
约束以使 btnInfo
出现在距离顶部 30 点和距离右边距 30 点处。请帮忙。
最佳答案
关于ios - 如何相对于父 View 的边距将 AddConstraint 添加到按钮,使其看起来距上边距 30 度,距右边距 30 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44893272/