1
我想在屏幕上水平平均分配未知數量的按鈕。我想知道是否可以基於彼此創建其間距。例如下面的代碼可以工作嗎?在SnapKit中,兩個視圖可以相互分隔嗎?
let button1 = UIButton()
let button2 = UIButton()
superview.addSubview(button1)
superview.addSubview(button2)
button1.snp_makeConstraints { (make) -> Void in
make.height.equalTo(100)
make.top.equalTo(50)
make.left.equalTo(superview.snp.left)
make.right.equalTo(button2.snp.right)
make.width.lessThanOrEqualToSuperview()
}
button2.snp_makeConstraints { (make) -> Void in
make.width.lessThanOrEqualToSuperview()
make.height.equalTo(100)
make.top.equalTo(50)
make.left.equalTo(button1.snp.left)
make.right.equalTo(superview.snp.right)
}
關於UIStackView的好建議絕對是一種更好的方式。 – SmedleyDSlap