Forked from dduan/UISegmentedControl+VerticalLayout.swift
Created
April 24, 2019 11:24
-
-
Save m760622/dd24dc14f7ea823461dcd01656abd43f to your computer and use it in GitHub Desktop.
Turns a UISegmentedControl into a vertical layout.
This file contains hidden or 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