Using Autolayout Visual Format with Swift?

后端 未结 9 1988
执笔经年
执笔经年 2021-02-01 14:57

I\'ve been trying to use the Autolayout Visual Format Language in Swift, using NSLayoutConstraint.constraintsWithVisualFormat. Here\'s an example of some code that

9条回答
  •  旧时难觅i
    2021-02-01 15:58

    this works for me with no error:

    let bar:[AnyObject]! = NSLayoutConstraint.constraintsWithVisualFormat(
      nil, options: NSLayoutFormatOptions(0), metrics: nil, views: nil)
    

    update

    the line above may not be compiled since the 1st and 4th parameters cannot be optionals anymore.

    syntactically those have to be set, like e.g. this:

    let bar:[AnyObject] = NSLayoutConstraint.constraintsWithVisualFormat("", options: NSLayoutFormatOptions(0), metrics: nil, views: ["": self.view])
    

    update

    (for Xcode 7, Swift 2.0)

    the valid syntax now requests the parameters's name as well, like:

    NSLayoutFormatOptions(rawValue: 0)
    

    NOTE: this line of code shows the correct syntax only, the parameters itself won't guarantee the constraint will be correct or even valid!

提交回复
热议问题