1

我有一个问题,我想要一个视图(indicatorView)的宽度等于一个按钮。我正在使用Snapkit,但我认为这个问题也应该与裸 NSLayoutConstraint 相关。这是我正在做的使indicatorView's宽度等于button.

indicatorView.width.equalTo(button.snp.width)

但是,这会使按钮的宽度等于指示器视图的宽度,而不是使指示器视图的宽度等于按钮的宽度。

如何指定关系的方向?那可能吗?

4

3 回答 3

1
indicatorView.translatesAutoresizingMaskIntoConstraints = false
indicatorView.widthAnchor.constraint(equalToConstant: button.widthAnchor).isActive = true
于 2017-10-09T07:02:53.557 回答
0
let f = indicatorView.frame
indicatorView.frame = CGRect(x: f.origin.x, y: f.origin.y: width: button.snp.width, height: f.height)
于 2017-10-09T00:49:03.007 回答
0

您是否将其包装在正确的封闭中?所以它应该看起来像:

indicatorView.snp.makeConstraints { (make) in
        make.width.equalTo(button)
}
于 2017-10-09T22:06:08.803 回答