我在tableviewCell中有一个视图,我想添加按钮并为视图添加此按钮的约束
喜欢facebook的问题
答案 0 :(得分:1)
因为你的问题不是很明确,我只能放弃这个:
YOURVIEW.addSubview(YOURBUTTON)
iOS 9 +
YOURVIEW.addSubview(YOURBUTTON)
YOURBUTTON.translatesAutoresizingMaskIntoConstraints = false
YOURBUTTON.topAnchor.constraintEqualToAnchor(YOURVIEW.topAnchor).active = true
YOURBUTTON.bottomAnchor.constraintEqualToAnchor(YOURVIEW.bottomAnchor).active = true
YOURBUTTON.leadingAnchor.constraintEqualToAnchor(YOURVIEW.leadingAnchor).active = true
YOURBUTTON.trailingAnchor.constraintEqualToAnchor(YOURVIEW.trailingAnchor).active = true
iOS 6 +
let view = ["yourButotn": YOURBUTTON]
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[yourButotn]-|", options: [], metrics: nil, views: views))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[yourButotn]-|", options: [], metrics: nil, views: views))
这将添加约束