UILabel高度? [英] UILabel height?

查看:141
本文介绍了UILabel高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用IB的uilabel设置并使用以下代码:

I have an uilabel setup with IB and with this code:

// setup label
sv.text =  @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation."; 
sv.lineBreakMode = UILineBreakModeWordWrap; 
sv.numberOfLines = 0;
[sv sizeToFit];

我的问题是,如何获得uilabel高度?

my question is, how do I get the uilabel height?

推荐答案

试试这个......

Try this one.....

            CGSize maximumSize1 = CGSizeMake(100, 9999);
            NSString *myString1 = @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
            UIFont *myFont1 = [UIFont boldSystemFontOfSize:14];//[UIFont fontWithName:@"Helvetica" size:14];


            UILabel *lbl_Title=[[UILabel alloc] init];
            lbl_Title.lineBreakMode=UILineBreakModeClip;
            CGSize myStringSize1 = [myString1 sizeWithFont:myFont1 
                                         constrainedToSize:maximumSize1 
                                             lineBreakMode:lbl_Title.lineBreakMode];
            lbl_Title.frame=CGRectMake(20, 10, myStringSize1.width, myStringSize1.height);
            lbl_Title.font=myFont1;
            //      lbl_Title.font=[UIFont boldSystemFontOfSize:14];
            lbl_Title.backgroundColor=[UIColor clearColor];
            lbl_Title.numberOfLines=100;
            lbl_Title.text=myString1;

这篇关于UILabel高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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