xcode 9 swfit4.1
// 属性传值
let attributeBtn = UIButton.init()
attributeBtn.translatesAutoresizingMaskIntoConstraints = false
attributeBtn.setTitle("属性传值", for: .normal)
attributeBtn.setTitleColor(UIColor.black, for: .normal)
self.view.addSubview(attributeBtn)
attributeBtn.addTarget(self, action: #selector(RootViewController.attributeBtnClicked), for: .touchUpInside)
attributeBtn.layer.borderColor = UIColor.green.cgColor
attributeBtn.layer.borderWidth = 3.0
// layout Views
let layoutViews:[String:AnyObject] = ["attributeBtn": attributeBtn]
//创建水平方向约束
self.view.addConstraints(NSLayoutConstraint.constraints(
withVisualFormat: "H:|-5-[attributeBtn]-5-|", options:.alignAllCenterX,
metrics: nil, views: layoutViews))
//创建垂直方向约束
self.view.addConstraints(NSLayoutConstraint.constraints(
withVisualFormat: "V:|-64-[attributeBtn(==50)]|",
options:NSLayoutFormatOptions.alignAllCenterX, metrics: nil, views: layoutViews))
网友评论