I am customizing an UISlider
for my app. I want the slider to be in vertical orientation, but the default UISlider
is in horizontal orientation. I couldn't find how to change a UISlider
's orientation.
How can I make a vertical slider in XCode?
I am customizing an UISlider
for my app. I want the slider to be in vertical orientation, but the default UISlider
is in horizontal orientation. I couldn't find how to change a UISlider
's orientation.
How can I make a vertical slider in XCode?
In case you are using auto layouts:
In your viewDidLoad, try:
It does not work with constraints, so the trick is to remove the constraints for your uislider. You might have to resize it manually by setting its frame property.
By default, a UISlider is horizontal (--). If you wish to make it vertical (|) then you must do this programmatically, probably with a
CGAffineTransform
. For example, you can add this snippet toviewDidLoad
or wherever you deem appropriate:I had a problem with :
because I had the code in ViewDidLoad method. Instead, I put the code in ViewDidAppear and it worked fine.
Edit: it doesn't have to be in the ViewDidAppear, ViewDidLoad works fine too (even better). You could disable auto-resize, or set a constraint for the slider you're rotating so the size doesn't change after rotation.