How to Change the UISlider to Vertical?

SeongHo picture SeongHo · Nov 14, 2011 · Viewed 22.7k times · Source

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?

Answer

PengOne picture PengOne · Nov 14, 2011

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 to viewDidLoad or wherever you deem appropriate:

CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI_2);
slider.transform = trans;