Last active
July 25, 2024 05:52
-
-
Save dduan/47d6eff4978acb85affc to your computer and use it in GitHub Desktop.
Turns a UISegmentedControl into a vertical layout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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