文本太大时,文本不显示在UILabel上。 [英] Text not displaying on UILabel when the text is too large.

查看:119
本文介绍了文本太大时,文本不显示在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-Regularsize:17]];
labelsize = [story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280,15000)lineBreakMode:NSLineBreakByWordWrapping];
commentsTextLabel.frame = CGRectMake(20,200,280,labelsize.height);
commentsTextLabel.text = story; //超过1000行

[self.view addSubview:commentsTextLabel];

当我调试我的代码时,我发现labelize.height出现在我的情况下13145.Still it没有显示。
如果我减少15000到11000,那么文本最终会显示在....



labelsize = [story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280,15000)lineBreakMode:NSLineBreakByWordWrapping];



<请帮帮我。
谢谢

解决方案

UILabel 将呈现其所有文字一旦进入后备缓冲区。 iOS设备只有有限的图形内存才能完成这项工作,因此一旦图形数据超过一定大小,它就会失败。



对于大量文本你应该使用核心文本或类似 UITextView 之类的东西,它可以更有效地按需呈现文本。


I have a text (Story of a book). I am taking UILabel to display it. But it is not showing me on view. I am using the following code:

    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];

When i debug my code, i found labelsize.height is coming out in my case 13145.Still it is not showing. If i descrease 15000 to 11000 , then text is showing on view with .... at last.

labelsize=[story sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];

Please help me out. Thanks

解决方案

UILabel will render all its text at once into a backing buffer. iOS devices only have a limited amount of graphics memory to do this work, so it will fail once the graphics data goes above a certain size.

For large amounts of text you should use Core Text or something like UITextView which renders its text on-demand much more efficiently.

这篇关于文本太大时,文本不显示在UILabel上。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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