1

在此处输入图像描述我正在创建一个 UILabel 用于在 iphone 应用程序中显示大约 16,000 行的文本。它在 ios 6 之前运行良好,但现在在 ios 6.0 或更高版本中无法正确显示。

标签中没有显示任何内容。它之前工作正常并且不知道其中出了什么问题。我在 Scrollview 上添加了 UILabel。标签的代码如下所示:=

infoUILabel.text = stringForLargeDescrition;
CGSize constraintSize;
    constraintSize.width = 285.0f;
    constraintSize.height = MAXFLOAT;

stringSizeforDescription = [strignForLabel sizeWithFont: [UIFont boldSystemFontOfSize: 5] constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap];
        infoUILabel.layer.cornerRadius = 10;    
        infoUILabel.layer.masksToBounds = YES;
        [infoUILabel setFrame:CGRectMake(20,135, 285, stringSizeforDescription.height)];
        CGRect frame = infoUILabel.frame;
        frame.size = [infoUILabel sizeThatFits:CGSizeMake(285, stringSizeforDescription.height)];
        infoUILabel.frame = frame;
        [infoUILabel alignTop];//this function will align the text to top of label
         backScrollView.contentSize = CGSizeMake(320, 230 + infoUILabel.frame.size.height);
     backScrollView.clipsToBounds = YES;

请建议,提前谢谢。

4

5 回答 5

2

使用 textview 显示动态文本解决了我的问题,代码如下:

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 135, 285, 200)];
    textView.text = @"Very large text";
    textView.scrollEnabled = NO;
    textView.delegate = self;
    textView.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
    textView.textColor = [UIColor darkGrayColor];
    textView.layer.cornerRadius = 10;
    textView.layer.masksToBounds = YES;
    textView.backgroundColor= [UIColor whiteColor];
    CGRect rect      = textView.frame;

 CGSize constraintSize;
constraintSize.width = 285.0f;
constraintSize.height = MAXFLOAT;
stringSizeforDescription = [strignForLabel sizeWithFont: [UIFont boldSystemFontOfSize: 12] constrainedToSize: constraintSize lineBreakMode: UILineBreakModeWordWrap];
    rect.size.height = stringSizeforDescription.height + 20;//20 is some extra margin value 
    textView.frame   = rect;

[scrollView addSubview:textView];
[textView sizeToFit];
于 2013-03-12T11:50:30.797 回答
0

您错过了要设置的 numberOfLines 属性。

添加 :

infoUILabel.numberOfLines = 0;

它应该工作。还要从您的代码中删除这两行:

frame.size = [infoUILabel sizeThatFits:CGSizeMake(285, stringSizeforDescription.height)];
infoUILabel.frame = frame;
于 2013-02-28T05:59:56.297 回答
0

试试这个对我有用:

CGFloat height = 44.0;

CGSize labelSize = CGSizeMake(200.0, 20.0);

NSString *strTemp;

NSString *sectionData = @"Lengthy text.......Lengthy text.......Lengthy text.......";

labelSize = [sectionData sizeWithFont: [UIFont boldSystemFontOfSize:12.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];

height =  (labelSize.height+40);

CGRect rect = lbl.frame;

rect.size.height = height;

lbl.frame = rect;
于 2013-02-28T08:19:07.097 回答
-1

添加

infoLabel.numberOfLines=0;

确保 MAXFLOAT 的值大于预期值

于 2013-02-28T06:05:53.083 回答
-1

您能否在设置 UILabel 的所有属性后,尝试在最后将文本设置为 UILabel。

于 2013-02-28T07:32:17.187 回答