UILabel 中的多行文本 [英] Multiple lines of text in UILabel
本文介绍了UILabel 中的多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法像 UITextView
一样在 UILabel
中包含多行文本,还是应该使用第二个?
Is there a way to have multiple lines of text in UILabel
like in the UITextView
or should I use the second one instead?
推荐答案
设置换行模式为自动换行,行数设置为0
:
Set the line break mode to word-wrapping and the number of lines to 0
:
// Swift
textLabel.lineBreakMode = .byWordWrapping
textLabel.numberOfLines = 0
// Objective-C
textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;
// C# (Xamarin.iOS)
textLabel.LineBreakMode = UILineBreakMode.WordWrap;
textLabel.Lines = 0;
恢复旧答案(供参考和愿意支持 iOS 6.0 以下的开发者):
Restored old answer (for reference and devs willing to support iOS below 6.0):
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
另一方面:无论如何,两个枚举值都会产生 0
.
On the side: both enum values yield to 0
anyway.
这篇关于UILabel 中的多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文