你好我是NSLayoutConstraintVisualFormat
的新手。请在下面找到以下代码来实现下面的设计。
请找到以下代码
代码段:
func addConstraintsWithFormat(format: String, views: UIView...) {
var viewsDictionary = [String: UIView]()
for (index, view) in views.enumerated() {
let key = "v\(index)"
view.translatesAutoresizingMaskIntoConstraints = false
viewsDictionary[key] = view
}
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
}
addConstraintsWithFormat(format: "H:|-1-[v0]-1-|", views: topBorderView)
addConstraintsWithFormat(format: "V:|-1-[v0(40)]-1-|", views:topBorderView)
addConstraintsWithFormat(format: "H:|-8-[v0]-8-[v1(80)]-8-|", views: nameLabel,codeLabel)
addConstraintsWithFormat(format: "V:|-4-[v0]-4-|", views: nameLabel)
addConstraintsWithFormat(format: "V:|-4-[v0]-4-|", views: codeLabel)
addConstraintsWithFormat(format: "H:|-15-[v0]|", views: flag)
addConstraintsWithFormat(format: "V:|-55-[v0]|", views: flag)
addConstraint(NSLayoutConstraint(item: flag, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 0, constant: 50))
addConstraint(NSLayoutConstraint(item: flag, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0, constant: 50))
addConstraintsWithFormat(format: "H:|-80-[v0(75)]|", views: placeholder)
addConstraintsWithFormat(format: "V:|-50-[v0(30)]|", views: placeholder)
addConstraintsWithFormat(format: "H:|-165-[v0(1)]|", views: seperatorView)
addConstraintsWithFormat(format: "V:|-60-[v0(45)]|", views: seperatorView)
addConstraintsWithFormat(format: "H:|-200-[v0(75)]|", views: placeholder1)
addConstraintsWithFormat(format: "V:|-50-[v0(30)]|", views: placeholder1)
addConstraintsWithFormat(format: "H:|-80-[v0(75)]|", views: buyingPriceLabel)
addConstraintsWithFormat(format: "V:|-80-[v0(30)]|", views: buyingPriceLabel)
addConstraintsWithFormat(format: "H:|-200-[v0(75)]|", views: sellingPriceLabel)
addConstraintsWithFormat(format: "V:|-80-[v0(30)]|", views: sellingPriceLabel)
addConstraintsWithFormat(format: "H:|-80-[v0(195)]|", views: lastUpdatedDate)
addConstraintsWithFormat(format: "V:|-120-[v0(30)]|", views: lastUpdatedDate)
addConstraintsWithFormat(format: "H:|-0-[v0(290)]|", views: thirtyDaysUpdateButton)
addConstraintsWithFormat(format: "V:|-150-[v0(40)]|", views: thirtyDaysUpdateButton)
addConstraintsWithFormat(format: "H:|-250-[v0(35)]|", views: buttonRightImage)
addConstraintsWithFormat(format: "V:|-152-[v0(35)]|", views: buttonRightImage)