我有一个问题,我想要一个视图(indicatorView
)的宽度等于一个按钮。我正在使用Snapkit
,但我认为这个问题也应该与裸 NSLayoutConstraint 相关。这是我正在做的使indicatorView's
宽度等于button
.
indicatorView.width.equalTo(button.snp.width)
但是,这会使按钮的宽度等于指示器视图的宽度,而不是使指示器视图的宽度等于按钮的宽度。
如何指定关系的方向?那可能吗?
我有一个问题,我想要一个视图(indicatorView
)的宽度等于一个按钮。我正在使用Snapkit
,但我认为这个问题也应该与裸 NSLayoutConstraint 相关。这是我正在做的使indicatorView's
宽度等于button
.
indicatorView.width.equalTo(button.snp.width)
但是,这会使按钮的宽度等于指示器视图的宽度,而不是使指示器视图的宽度等于按钮的宽度。
如何指定关系的方向?那可能吗?
indicatorView.translatesAutoresizingMaskIntoConstraints = false
indicatorView.widthAnchor.constraint(equalToConstant: button.widthAnchor).isActive = true
let f = indicatorView.frame
indicatorView.frame = CGRect(x: f.origin.x, y: f.origin.y: width: button.snp.width, height: f.height)
您是否将其包装在正确的封闭中?所以它应该看起来像:
indicatorView.snp.makeConstraints { (make) in
make.width.equalTo(button)
}