是否可以自动布局UISlider的宽度

时间:2016-10-17 09:40:50

标签: objective-c uislider pure-layout

我正在使用PureLayoutUISlider放在两个按钮之间,如下所示:

[self.slider autoPinEdge:ALEdgeLeading  toEdge:ALEdgeTrailing   ofView:self.leftButton withOffset:10.0f];
[self.slider autoPinEdge:ALEdgeTrailing toEdge:ALEdgeLeading    ofView:self.rightButton withOffset:10.0f];
[self.slider autoAlignAxisToSuperviewAxis:ALAxisHorizontal];

UISlider是否有可能在leftButtonrightButton之间自动设置其宽度?

1 个答案:

答案 0 :(得分:1)

要自动布局UISlider的宽度,您应该提供左右按钮的宽度。此外,您必须将它们固定到超视图边缘。然后你就可以将滑块的LEFT边缘固定到leftButton的右边缘,将滑块的右边缘固定到rightButton的左边缘。

示例代码:

cell.contentView.addSubview(leftButton)
cell.contentView.addSubview(slider)
cell.contentView.addSubview(rightButton)

rightButton.autoPinEdgeToSuperviewEdge(.Top)
rightButton.autoPinEdgeToSuperviewEdge(.Right)
rightButton.autoSetDimension(.Width, toSize: 100)
rightButton.autoSetDimension(.Height, toSize: 50)

leftButton.autoPinEdgeToSuperviewEdge(.Top)
leftButton.autoPinEdgeToSuperviewEdge(.Left)
leftButton.autoSetDimension(.Width, toSize: 100)
leftButton.autoSetDimension(.Height, toSize: 50)

slider.autoPinEdge(.Leading, toEdge: .Trailing, ofView: leftButton, withOffset : 5)
slider.autoPinEdge(.Trailing, toEdge: .Leading, ofView: rightButton, withOffset : -5)
slider.autoPinEdgeToSuperviewEdge(.Top)

enter image description here