Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put UISlider vertical?

I want to put UISlider in vertically. I have no idea about this, so please help me for this.

like image 475
MD. Avatar asked Mar 04 '10 05:03

MD.


2 Answers

You have to do this programaticaly. Assuming your UISlider is bound to a variable called slider, add this code in your viewDidLoad method in ViewController.m:

- (void)viewDidLoad {

    [super viewDidLoad];

    CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI * 0.5);
    slider.transform = trans;
}

Let me know if you need any more help on this..

like image 77
ravinsp Avatar answered Nov 12 '22 16:11

ravinsp


As of Xcode 4.2, you can sort of do the same in Interface Builder.

  • Create a slider
  • Show the "Identity Inspector"
  • Add a "User Defined Runtime Attribute"
  • Set the key path to "layer.transform.rotation.z", the type as "String" ("Number" won't allow floating point values) (possible since Xcode 5) and the value to "-1.570795" (-π/2).

Unfortunately, it will still appear as horizontal in Interface Builder.

But you can position the center and don't need to create a custom class, so it might be useful enough in some cases. The effect is the same as ravinsp's code.

like image 30
nschum Avatar answered Nov 12 '22 15:11

nschum