ios - 如果文本高度太大,则标签不显示

标签 ios swift swift3 xcode8

我试图用 Scroll View 中的 Label 显示一些非常长的文本,但它没有显示。

当我把较小的字体显示出来时。

为什么会发生这种情况以及如何解决?

是不是线路太多了?其他一些文字肯定超过200行,显示正常,但是这个文字比它们还要长。

使用 print(text.characters.count) 我得到该文本的 15884。

最佳答案

来自 Apple Document Of UIView :

In iOS 2.x, the maximum size of a UIView object is 1024 x 1024 points. In iOS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. It is in your best interests to keep view sizes as small as possible. Regardless of which version of iOS is running, you should consider tiling any content that is significantly larger than the dimensions of the screen.

由于 UILabel 是 UIView 的子类,当字体较大时,长度为 15884 的文本似乎太长,UILabel 无法处理。

我想你可以做一些实验来找到可接受的字体大小。但是,我建议对这么长的文本使用 UITextView 而不是 UILabel。

关于ios - 如果文本高度太大,则标签不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39969471/

相关文章:

iphone - numberOfLines=2 的 UILabel 使用什么约束高度? (使用 [NSString sizeWithFont...])

ios - Objective c post 请求不发送数据

iOS自定义 View ,更改UILabel textColor/isHidden不起作用

ios - ContentInset 在 popViewController 之后自动改变

ios - 错误: 'Cannot call value of non-function type' on Swift 3

ios - swift 3 : Can not convert value of type 'int' to expected argument type 'DispatchQueue.GlobalQueuePriority'

html - iOS Hpple HTML 解析

ios - Swift 2.0 ContactsUI 框架

swift - MKDirections calculateWithCompletionHandler

ios - 由于未捕获的异常 'NSInternalInconsistencyException' - HTTPS 错误而终止应用程序