简体   繁体   English

在UILabel中添加多行文本

[英]Add Multiple lines of text in UILabel

Any way to have multiple lines of text in UILabel like in the UITextView ? 有什么办法可以像在UITextView那样在UILabel包含多行文本?

I dont wish to use more than 1 label in the view. 我不希望在视图中使用多个标签。

Just use this code in your Program 只需在您的程序中使用此代码

textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;

Yes this can be done by setting the numerOfLines property to the number of lines you want to display. 是的,这可以通过将numerOfLines属性设置为要显示的行数来完成。 Or set it to 0 if you just want to be able to add as many lines as you want. 或将其设置为0如果您仅希望能够添加任意多的行)。

You can check out this answer which has everything you want 您可以查看此答案 ,其中包含您想要的一切

You can also set Properties like numberoflines and linebreakMode 您还可以设置属性,例如numberoflineslinebreakMode

have look to documentation as well 也看文档

使用UILabel的numberOfLines属性,并为多行分配0

textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;

set the lineBreakMode and numberOfLines property of UILabel and set the frame as see the multiple lines. 设置UILabel的lineBreakModenumberOfLines属性,并设置框架,如多行所示。

yourLabel.lineBreakMode = UILineBreakModeWordWrap;
yourLabel.numberOfLines = 0;
yourLabel.frame = CGRectMake(0,0,320,150);

yes,this is possible in .xib file select your label you found Lines option set value that you want to ie line 3 是的,可以在.xib文件中选择要找到的标签,即要选择的选项设置值,即第3行

if you creating label programmatic than 如果您以程序方式创建标签

 lbl.numberOfLines = 0;

CGRect currentFrame = myLabel.frame;
CGSize max = CGSizeMake(lbl.frame.size.width, 500);
CGSize expected = [myString sizeWithFont:lbl.font constrainedToSize:max lineBreakMode:lbl.lineBreakMode]; 
currentFrame.size.height = expected.height;
lbl.frame = currentFrame;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM