Is there any possibility to make UISegmentedControl with multiple lines of text in iOs 9+?
So far i've tryed:
- Variants from SO topics: This, this and this one
Make an extension:
extension UISegmentedControl { func makeMultiline(numberOfLines: Int) { for segment in self.subviews { let labels = segment.subviews.filter { $0 is UILabel } // [AnyObject] labels.map { ($0 as UILabel).numberOfLines = numberOfLines } } } }
Inherit from UISegmentedControl and set new class to SegmentedControl in Identity Inspector
class MultilineSegmentedControl: UISegmentedControl { override func didMoveToSuperview() { for segment in subviews { for subview in segment.subviews { if let segmentLabel = subview as? UILabel { segmentLabel.numberOfLines = 2 } } } } }
Set image with text instead of title and change frame of UISegmentedControl in
viewDidLayoutSubviews()
method. It makes UISegmentedControl height larger, but image keeps it's height as if UISegmentedControl didn't enlarge and on first interaction UISegmentedControl shrinks to it's default height.