首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILabel高度?

UILabel高度?
EN

Stack Overflow用户
提问于 2010-08-15 00:42:10
回答 3查看 6.3K关注 0票数 0

我有一个uilabel设置与IB和以下代码:

代码语言:javascript
复制
// 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的高度?

EN

回答 3

Stack Overflow用户

发布于 2011-11-09 17:51:59

试试这个。

代码语言:javascript
复制
            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;
票数 4
EN

Stack Overflow用户

发布于 2010-08-17 16:11:16

检查边界属性。

代码语言:javascript
复制
sv.bounds.size.height
票数 3
EN

Stack Overflow用户

发布于 2011-04-20 16:22:15

以下任何一种方法都可以解决这个问题。

代码语言:javascript
复制
<ullabel>.frame.size.height
<uilabel>.bounds.size.height

使用NSLog查看...

代码语言:javascript
复制
NSLog(@"%f", myLabel.bounds.size.height);
NSLog(@"%f", myLabel.frame.size.height);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3484218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档