is it possible to autolayout the width of the UISlider

341 Views Asked by At

I am using PureLayout to put a UISlider between 2 buttons as below:

[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];

Is it possible that the UISlider automatically sets its width between the leftButton and the rightButton ?

1

There are 1 best solutions below

0
On BEST ANSWER

To autolayout the width of UISlider you should provide the width of left and right button. Also, you have to pin them to the superview edges. Then you're able to pin LEFT edge of slider to RIGHT edge of leftButton, and RIGHT edge of slider to LEFT edge of rightButton.

Example code :

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