UILabel中的多行文本 [英] Multiple lines of text in UILabel

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

问题描述

有一种方法可以在 UITabel 中有多行文本,例如 UITextView 第二个?

Is there a way to have multiple lines of text in UILabel like in the UITextView or should I use the second one instead?

推荐答案

我找到了一个解决方案。

I found a solution.

只需要添加以下代码:

// Swift
textLabel.lineBreakMode = .ByWordWrapping // or NSLineBreakMode.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屋!

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