How can I make a vertical slider in swift?

Options 1:

In Swift 4:

-M_PI_2 is deprecated so Use Double.pi / 2

verticalSlider.transform = CGAffineTransform(rotationAngle: CGFloat(-Double.pi / 2))

OR

Options 2: for All Objective C and Swift

Key path = layer.transform.rotation.z 
Type     =  String
Value    = -1.570795

enter image description here

Most Imp Note: before and After keypath No Space


Use OOP. If you define this rotation as an Extension on UIView, then not only the UIView but also all subclasses that inherit from UIView can be rotated. This of course includes UISlider, but also UILabel, UIButton and about 200? other subclasses... see here list of subclasses for UIView

 extension UIView
 {
    func makeVertical()
    {
         transform = CGAffineTransform(rotationAngle: -CGFloat.pi / 2)
    }
 }

  // usage example:
  sldBoilerTemperature.makeVertical()  

It's good to be aware of inheritance, saves a lot of work. For many Swift extensions to make, it might be a good idea trying to move it upwards in the class hierarchy, like in this example.


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))
        }
    }
}