我试图让 Visual Format Language 快速工作,但我无法通过一个简单的例子让它工作。我试图让标签显示在左上角以外的其他地方。这就是它现在的显示方式:
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
let label = UILabel()
label.text = "Label 1"
label.sizeToFit()
self.view.addSubview(label)
self.view.translatesAutoresizingMaskIntoConstraints = false
let views = Dictionary(dictionaryLiteral: ("label", label))
let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-30-[label]-|",
options: [],
metrics: nil,
views: views)
self.view.addConstraints(horizontalConstraints)
let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-30-[label]-|",
options: [],
metrics: nil,
views: views)
self.view.addConstraints(verticalConstraints)
}
任何人都可以看到有什么问题吗?