我正在学习通过代码在 VFL 中编写约束
我已将 View 水平居中,如下所示:
let constraintY = NSLayoutConstraint.constraintsWithVisualFormat(
"H:[superview]-(<=1)-[collaboratorView]",
options: NSLayoutFormatOptions.AlignAllCenterY,
metrics: nil,
views: ["superview":self.assetsView, "collaboratorView":collaboratorView])
但我想知道如何将约束写入 topLayoutGuide 在 Storyboard中看起来像那样
我最终得到了这样的结果,但它不起作用;(
let bar = NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[collaboratorView]",
options: [NSLayoutFormatOptions.AlignAllTop],
metrics: nil,
views: ["collaboratorView":self.collaboratorView])
最佳答案
您可以定义如下:
let views : [String : AnyObject] = ["collaboratorView": collaboratorView,
"topLayoutGuide": topLayoutGuide,
"bottomLayoutGuide": bottomLayoutGuide]
// 2
var allConstraints = [NSLayoutConstraint]()
// 3
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:[collaboratorView]-12-[topLayoutGuide]",
options: [],
metrics: nil,
views: views)
allConstraints += verticalConstraints
关于ios - 如何在 VFL 中编写 topLayoutGuide 约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36862959/