gpt4 book ai didi

ios - 如何在 VFL 中编写 topLayoutGuide 约束

转载 作者:可可西里 更新时间:2023-11-01 01:36:31 26 4
gpt4 key购买 nike

我正在学习通过代码在 VFL 中编写约束

我的 View 水平居中:

let constraintY = NSLayoutConstraint.constraintsWithVisualFormat(
"H:[superview]-(<=1)-[collaboratorView]",
options: NSLayoutFormatOptions.AlignAllCenterY,
metrics: nil,
views: ["superview":self.assetsView, "collaboratorView":collaboratorView])

但我想知道如何将约束写入 topLayoutGuide在 Storyboard 中看起来像那样 enter image description here

我已经结束了这样的事情,但它不起作用;(

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com