How to put UISlider upright?

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

+42
math objective-c iphone uislider
Mar 04 '10 at 5:13
source share
5 answers

You must do this programmatically. Assuming your UISlider is associated with a variable called slider , add this code to 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 more help on this.

+104
Mar 04
source share
β€” -

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

  • Create a slider
  • Show "Person Inspector"
  • Add "Custom Runtime Attribute"
  • Set the key path to "layer.transform.rotation.z", type "String" ( "Number" will not allow floating point values) (possibly starting with Xcode 5), and the value is "-1.570795" (-Ο€ / 2).

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

But you can position the center and not create your own class, so in some cases it can be quite useful. The effect is the same as ravinsp code.

+30
Jun 29 '12 at 12:32
source share

Swift 3:

 slider.transform = slider.transform.rotated(by: CGFloat(0.5 * Float.pi)) 

// Use 1.5 to invert the slider shadow if you want

+6
Jan 20 '17 at 12:02 on
source share

If you work with car markets:

In your DidLoad view, 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 restrictions, so the trick is to remove the restrictions for your uislider. You may need to resize it manually by setting its frame property.

+4
Mar 06 '14 at 7:07
source share

Using IBOutlet and setter observers. If you want the maximum to be below, divide the number by a positive 2

 @IBOutlet weak var slider: UISlider! { didSet { slider.transform = CGAffineTransform(rotationAngle: .pi / -2) } } 
0
Jun 21 '18 at 0:06
source share



All Articles