本文介绍了我可以垂直显示 UISegmentedControl 对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人可以教我如何在垂直方向而不是水平方向显示 UISegmentedControl 对象?
Is there anyone who can teach me how to show an UISegmentedControl object in vertical direction, instead of in horizontal direction?
推荐答案
Ben 的回答 +1,虽然旋转分段控件也会旋转里面的文本.从不畏惧!我们只需要旋转内部标签,如下所示:
+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 对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!