我有一段文字(一本书的故事)。我正在使用 UILabel 来显示它。但它并没有让我看到。我正在使用以下代码:
CGSize labelsize;
UILabel *commentsTextLabel = [[UILabel alloc] init];;
[commentsTextLabel setNumberOfLines:0];
commentsTextLabel.textColor = [UIColor blackColor];
[commentsTextLabel setBackgroundColor:[UIColor clearColor]];
[commentsTextLabel setFont:[UIFont fontWithName:@"ACaslonPro-Regular"size:17]];
labelsize=[story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];
commentsTextLabel.frame=CGRectMake(20, 200, 280, labelsize.height);
commentsTextLabel.text = story;// more than 1000 lines
[self.view addSubview:commentsTextLabel];
当我调试我的代码时,我发现 labelsize.height 在我的案例 13145 中出现了。它仍然没有显示。 如果我将 15000 减少到 11000,那么文本最终会显示为 ....。
labelsize=[story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];
请帮帮我。 谢谢
最佳答案
UILabel
会将其所有文本一次呈现到后备缓冲区中。 iOS 设备只有有限的图形内存来完成这项工作,因此一旦图形数据超过一定大小,它就会失败。
对于大量文本,您应该使用 Core Text 或类似 UITextView
的东西,它可以更有效地按需呈现文本。
关于iphone - 当文本太大时,文本不会显示在 UILabel 上。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15764402/