Skip to content

Instantly share code, notes, and snippets.

@dduan
Last active July 25, 2024 05:52
Show Gist options
  • 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