Can I show an UISegmentedControl object in vertical?

Spread the love

Question Description

Is there anyone who can teach me how to show an UISegmentedControl object in vertical direction, instead of in horizontal direction?

Practice As Follows

+1 for Ben’s answer, although rotating the segmented control also rotates the text inside. Never fear! We just have to rotate the inside labels, like so:

    NSArray *arr = [segmentedControl subviews];
    for (int i = 0; i < [arr count]; i++) {
    UIView *v = (UIView*) [arr objectAtIndex:i];
    NSArray *subarr = [v subviews];
        for (int j = 0; j < [subarr count]; j++) {
            if ([[subarr objectAtIndex:j] isKindOfClass:[UILabel class]]) {
                UILabel *l = (UILabel*) [subarr objectAtIndex:j];
                l.transform = CGAffineTransformMakeRotation(- M_PI / 2.0); //do the reverse of what Ben did
            }
        }
    }

Swift 2 version:

for view in segmentedControl.subviews {
    for subview in view.subviews {
        if subview.isKindOfClass(UILabel) {
            subview.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI / 2.0))
        }
    }
}

Leave a Comment