Skip to content

Instantly share code, notes, and snippets.

@dduan
Last active April 19, 2023 14:50
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dduan/47d6eff4978acb85affc to your computer and use it in GitHub Desktop.
Save dduan/47d6eff4978acb85affc to your computer and use it in GitHub Desktop.
Turns a UISegmentedControl into a vertical layout.
import UIKit
extension UISegmentedControl {
func goVertical() {
self.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
for segment in self.subviews {
for segmentSubview in segment.subviews {
if segmentSubview is UILabel {
(segmentSubview as UILabel).transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
}
}
}
}
func restoreHorizontal() {
self.transform = CGAffineTransformIdentity
for segment in self.subviews {
for segmentSubview in segment.subviews {
if segmentSubview is UILabel {
(segmentSubview as UILabel).transform = CGAffineTransformIdentity
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment