How can I make a vertical slider in swift?

cross picture cross · Apr 19, 2015 · Viewed 17.5k times · Source

I was wondering how I can create a vertical slider in swift.

I have tried using .transform and then adding a rotate but this returned an exception and rotated the whole screen. I just need a vertical slider.

I was wondering if anyone know of a way to rotate a slider in swift?

Thanks

Answer

CryingHippo picture CryingHippo · Apr 19, 2015

Assuming you are talking about UISlider :

You were looking in a right direction but probably applied AffineTransformation to the wrong item... You should use UISlider.transform to change it orientation. Here is working code (I did add UISlider using InterfaceBuilder):

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var verticalSlider: UISlider!{
        didSet{
            verticalSlider.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI_2))
        }
    }
}