UI标签高度?

发布于 2024-09-14 01:02:17 字数 1015 浏览 6 评论 0原文

我使用 IB 和以下代码设置了 uilabel:

// 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 高度?

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];

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

殊姿 2024-09-21 01:02:17

试试这个......

            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;

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;
迷离° 2024-09-21 01:02:17

以下任一方法都可以解决问题...

<ullabel>.frame.size.height
<uilabel>.bounds.size.height

使用 NSLog 来看看...

NSLog(@"%f", myLabel.bounds.size.height);
NSLog(@"%f", myLabel.frame.size.height);

either of the following should do the trick...

<ullabel>.frame.size.height
<uilabel>.bounds.size.height

Use NSLog to take a look...

NSLog(@"%f", myLabel.bounds.size.height);
NSLog(@"%f", myLabel.frame.size.height);
痕至 2024-09-21 01:02:17

检查边界属性。

sv.bounds.size.height

Check the bounds property.

sv.bounds.size.height
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文