title: How to rotate UISegmentedControl and increase the size to fit any amount of text
body: <p>I've been trying to use UISegmentedControl as a multiple-choice selection tool. I thought that if I could rotate it 90 degrees (as well as the text inside) and expand the cells, it would be a very fluid tool. However no matter what I try it keeps giving me variations of this<a href="https://i.stack.imgur.com/PLudY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PLudY.png" alt="broken UISegmentedControl"></a></p>
  
  <p>By the way, this is inside a UICollectionView. Here is my code for the UICollectionViewCell</p>
  
  <pre><code>class customCollectionCell: UICollectionViewCell {
  @IBOutlet weak var questionLabel: UILabel!
  @IBOutlet weak var questionDescriptionLabel: UILabel!
  @IBOutlet weak var viewForSegment: UIView!
  var segment: CustomSegmentedControl!
  
  func heightForView(text:String, width:CGFloat) -&gt; CGFloat{
      let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max))
      label.numberOfLines = 0
      label.lineBreakMode = NSLineBreakMode.ByWordWrapping
      label.text = text
  
      label.sizeToFit()
      return label.frame.height
  }
  
  func loadQuestions(choices: [String], pointIndex: [Int]) {
      segment = CustomSegmentedControl(items: choices)
      segment.transform = CGAffineTransformMakeRotation(CGFloat(M_PI / 2.0));
      for view in segment.subviews {
          for sv in view.subviews {
              if sv.isKindOfClass(UILabel){
                  let subview: UILabel = sv as! UILabel
                  subview.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI / 2.0))
                  subview.addConstraint(NSLayoutConstraint(item: subview,
                      attribute: NSLayoutAttribute.Height,
                      relatedBy: NSLayoutRelation.Equal,
                      toItem: nil,
                      attribute:NSLayoutAttribute.NotAnAttribute,
                      multiplier:1,
                      constant: heightForView(subview.text!, width: self.viewForSegment.frame.width)))
                  subview.addConstraint(NSLayoutConstraint(item: subview,
                      attribute: NSLayoutAttribute.Width,
                      relatedBy: NSLayoutRelation.Equal,
                      toItem: nil,
                      attribute:NSLayoutAttribute.NotAnAttribute,
                      multiplier:1,
                      constant: self.viewForSegment.frame.width))
              }
          }
      }
      segment.pointIndex = pointIndex
      /*
      self.addConstraint(NSLayoutConstraint(item: segment, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.LeftMargin, multiplier: 1, constant: 0))
      self.addConstraint(NSLayoutConstraint(item: segment, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.BottomMargin, multiplier: 1, constant: 0))
      self.addConstraint(NSLayoutConstraint(item: segment, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.RightMargin, multiplier: 1, constant: 0))
      self.addConstraint(NSLayoutConstraint(item: segment, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: questionDescriptionLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 20))
      segment.frame = CGRect(origin: CGPoint(x: questionLabel.x, y: ), size: segment.systemLayoutSizeFittingSize(UILayoutFittingExpandedSize))
      */
  
      segment.bounds.size = segment.systemLayoutSizeFittingSize(UILayoutFittingExpandedSize)
      viewForSegment.addSubview(segment)
      viewForSegment.frame.size = viewForSegment.systemLayoutSizeFittingSize(UILayoutFittingExpandedSize)
  }
  </code></pre>
  
  <p>}</p>