Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change the UISlider to Vertical?

Tags:

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?

like image 919
SeongHo Avatar asked Nov 14 '11 06:11

SeongHo


2 Answers

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; 
like image 65
PengOne Avatar answered Oct 04 '22 04:10

PengOne


In case you are using auto layouts:

In your viewDidLoad, try:

UIView *superView = self.sizeSlider.superview; [self.sizeSlider removeFromSuperview]; [self.sizeSlider removeConstraints:self.view.constraints]; self.sizeSlider.translatesAutoresizingMaskIntoConstraints = YES; self.sizeSlider.transform = CGAffineTransformMakeRotation(M_PI_2); [superView addSubview:self.sizeSlider]; 

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.

like image 28
Antzi Avatar answered Oct 04 '22 04:10

Antzi