iphone - 当文本太大时,文本不会显示在 UILabel 上。

标签 iphone ios objective-c uilabel

我有一段文字(一本书的故事)。我正在使用 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/

相关文章:

objective-c - (BOOL)窗口应该关闭 :(id)sender doesn't work in view that i set as contentview of mainmenu's window

iOS 7 UITableView 问题 - 尝试设置滑动以删除已有单元格的单元格

iphone - 如何在 Xcode 中设置线程特定断点?

ios - 使用 xcode 4.5 的自定义项目模板

ios - 尝试更新表单提交 SwiftUI 上的先前 View

ios - 数组和表格 View : only add new items

iphone - 如何在 ios 中使用 URL 和 NSString 在 UIImageView 上显示图像?

iphone - 呈现 UINavigationController 多个深度 View ,作为初始 View

iphone - insertNewObjectForEntityForName : inManagedObjectContext: returning NSNumber bug?

ios - SKSpriteNode zrotation M_PI真气人