How to create a vertical UISlider
June 21st, 2010 No Comments »
I’m sure that all of you wondered how to do this, and actually it’s pretty easy.
In my case i needed a zoom slider, and i want it vertical, as you can see there is no rotation option in interface builder, so how can you do that ? you can create an vertical slider from code: just add the slider from interface builder, and create an outlet, connect it to the slider and enter this in the viewDidLoad method of the view controller, you should have something like this :
- (void)viewDidLoad {
zoomSlider_.transform = CGAffineTransformRotate(zoomSlider_.transform, M_PI/2);
[super viewDidLoad];
}
The CGAffineTransformRotate function accepts 2 parameters, the first one is the current transformation and the second one is the number of radians to rotate (a radian = pi = 180 degree, so 90 = pi/2).