title: Vertical UISlider constraints
body: <p>I am creating a vertical UISlider. I have created the view it is in using all code. (the rest of the storyboard elements are constrained using interface builder)</p>
  
  <p>From what I have read, to create a vertical UISlider you give the UISlider a width and then rotate it. Since the height of the container that the UISlider sits in varies by screen size I do not want to give it a fixed height (width).</p>
  
  <p>This is what I was thinking</p>
  
  <pre><code>    // Mark: Slider View
  
      let leftSlider = UISlider()
      let centerSlider = UISlider()
      let rightSlider = UISlider()
  
      let colorSliders = [leftSlider, centerSlider, rightSlider]
  
      for slider in colorSliders {
  
          slider.translatesAutoresizingMaskIntoConstraints = false
          sliderContainer.addSubview(slider)
  
          let w = sliderContainer.bounds.width
          slider.bounds.size.width = w
          slider.center = CGPoint(x: w/2, y: w/2)
          slider.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI_2))
  
          slider.value = 0
          slider.minimumValue = 0
          slider.maximumValue = 255
  
          let sliderTopConstraint = slider.topAnchor.constraint(equalTo: centerHiddenView.bottomAnchor, constant: 5)
          let sliderBottomConstraint = slider.bottomAnchor.constraint(equalTo: sliderContainer.bottomAnchor, constant: 5)
  
          NSLayoutConstraint.activate([sliderTopConstraint, sliderBottomConstraint])
          slider.backgroundColor = .purple
          slider.isEnabled = true
          slider.isUserInteractionEnabled = true
  
      }
  
      let sliderContainerWidth: CGFloat = sliderContainer.frame.width
  
  
      let centerSliderHorizontalConstraints = centerSlider.centerXAnchor.constraint(equalTo: sliderContainer.centerXAnchor)
  
      let widthConstraint = centerSlider.widthAnchor.constraint(equalToConstant: sliderContainerWidth)
  
      let centerSliderWidthConstraint = centerSlider.widthAnchor.constraint(equalToConstant: 90)
  
      NSLayoutConstraint.activate([centerSliderHorizontalConstraints, centerSliderWidthConstraint, widthConstraint])
  </code></pre>
  
  <p>But when I run it I get this</p>
  
  <p><a href="https://i.stack.imgur.com/SHpm3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SHpm3.png" alt="enter image description here"></a></p>
  
  <p>which is far better than what I had earlier today. However, I would like the slider to be normal width..and well look normal just vertical</p>
  
  <p>Any ideas on what I missed?
  (Oh ignore that little purple offshoot to the left, that is the other 2 sliders that I added but didn't constrain yet.)</p>