Using Autolayout Visual Format with Swift?

后端 未结 9 1967
执笔经年
执笔经年 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条回答
  •  温柔的废话
    2021-02-01 15:43

    // topLayoutGuide constraint
        var views: NSMutableDictionary = NSMutableDictionary()
        views.setValue(taskNameField, forKey: "taskNameField")
        views.setValue(self.topLayoutGuide, forKey: "topLayoutGuide")
        let verticalConstraint = "V:[topLayoutGuide]-20-[taskNameField]"
        let constraints:[AnyObject]! = NSLayoutConstraint.constraintsWithVisualFormat(verticalConstraint, options: NSLayoutFormatOptions(0), metrics: nil, views: views)
        self.view.addConstraints(constraints)
    
    // bottomLayoutGuide constraint
    
        var views: NSMutableDictionary = NSMutableDictionary()
        views.setValue(logoutButton, forKey: "logoutButton")
        views.setValue(self.bottomLayoutGuide, forKey: "bottomLayoutGuide")
        let verticalConstraint = "V:[logoutButton]-20-[bottomLayoutGuide]"
        let constraints:[AnyObject]! = NSLayoutConstraint.constraintsWithVisualFormat(verticalConstraint, options: NSLayoutFormatOptions(0), metrics: nil, views: views)
        self.view.addConstraints(constraints)
    

提交回复
热议问题