UI分段控件上的多行文本 [英] Multiline Text On UIsegment Control

查看:85
本文介绍了UI分段控件上的多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个默认样式(白色)的UISegmentControl。我想在上面添加文字。但我想要提出的文字是一篇长篇文章。

I have a UISegmentControl with default style (White). I want to add text on it. But the text that i want to put on it is a long text.

我必须在段的2行显示文字。但是我不必提高段的宽度因为屏幕宽度极限和没有分段。

I have to show the text in 2 lines of a segment. But i dont have to raise the width of the segment Because of screen width limit & no of segments.

我曾尝试以编程方式在分段控件上添加标签,但我的标签未显示。虽然我们可以使用XIB在分段控件上添加标签。但是由于文本的动态性和段控制,我必须以编程方式绘制段控制&也将文字放在上面。

指导将不胜感激。

推荐答案

朋友段控制器已将标签作为子视图,因此此代码有助于实现多行文本分段控制

Hi friend segment controller already have the label as the subview, so this code is helpful to achieve the multiline text to segment control

for (id segment in [segmentedControl subviews]) 
{
    for (id label in [segment subviews]) 
    {
        if ([label isKindOfClass:[UILabel class]])
        {
            //hear u add any of delegate function to increase the height and other label functionality in this 
            [label setTextAlignment:UITextAlignmentCenter];
            [label setFont:[UIFont boldSystemFontOfSize:12]];
//to adjust the label size manually with respect to text use below code
  CGSize labelSize = CGSizeMake(100, 80);
  CGSize theStringSize = [label.text sizeWithFont:label.font constrainedToSize:labelSize];
  CGRect frame = label.frame;
  frame.size = theStringSize; 

        }
    }           
}

有一个美好的一天

这篇关于UI分段控件上的多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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