我可以垂直显示UISegmentedControl对象吗? [英] Can I show an UISegmentedControl object in vertical?

查看:66
本文介绍了我可以垂直显示UISegmentedControl对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人可以教我如何在垂直方向而不是水平方向显示UISegmentedControl对象?

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

推荐答案

+1表示Ben的答案,尽管旋转分段控件也会旋转内部文本.从不畏惧!我们只需要旋转内部标签,就像这样:

+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版本:

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))
        }
    }
}

这篇关于我可以垂直显示UISegmentedControl对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆