是否可以创建多行UISegmentedControl? [英] Is it possible to create multi line UISegmentedControl?

查看:332
本文介绍了是否可以创建多行UISegmentedControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的分段控件中有相对较长的文本项,所以我需要在某些点打破文本。是否可以使用换行符?我知道在按钮上我需要设置换行到自动换行,但是如何为UISegmentedControl设置它。

I have a relative longer text items in my segmented control so I need to break text at certain points. Is it possible to use line breaks? I know at buttons I need to set line break to word wrap, but how to to set it for UISegmentedControl.

推荐答案

如果你有一个标准的 UISegmentedControl 你可以使用以下想法:

if you have a standard UISegmentedControl you can use the following idea:

[_segmentedControl.subviews enumerateObjectsUsingBlock:^(UIView * obj, NSUInteger idx, BOOL *stop) {
    [obj.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([obj isKindOfClass:[UILabel class]]) {
            UILabel *_tempLabel = (UILabel *)obj;
            [_tempLabel setNumberOfLines:0];
        }
    }];     
}];

您可能需要设置 height 您的实例也是。

you may need to set the height of your instance as well.

注意:我需要添加一点警告关于 - 正如rmaddy也正确指出的那样 - 这是一个非常脆弱的解决方案,因为如果分段控件的视图层次结构将在未来的iOS版本中被更改,那么代码可能无法正常工作。

NOTE: I need to add a little warning about – as rmaddy has also pointed out correctly – this is a quite fragile solution, because if the segmented control's view hierarchy would be changed in the future iOS versions that code may not work properly anymore.

这篇关于是否可以创建多行UISegmentedControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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