【发布时间】:2013-04-02 12:42:05
【问题描述】:
我有一个文本(一本书的故事)。我正在使用 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];
当我调试我的代码时,我发现 labelize.height 在我的案例 13145 中出现。但它仍然没有显示。 如果我将 15000 减少到 11000 ,那么文本最终会显示在视图中。
labelsize=[故事 sizeWithFont:cmetsTextLabel.font constrainedToSize:CGSizeMake(280, 15000) lineBreakMode:NSLineBreakByWordWrapping];
请帮帮我。 谢谢
【问题讨论】:
-
你为什么不用 UITextView....?
-
使用不可编辑的UITextView不是更好吗?否则,请尝试在计算标签大小时将 MAXFLOAT 设置为高度约束。
-
这里的labelsize是指什么类型的变量?
-
我不想在某些部分使用滚动,我的要求是滚动整个视图。这就是我不使用 UITextView 的原因。
-
我用一些较小的文本来调试 labelize.height 是正确的。有人可以在你最后实现吗?
标签: iphone ios objective-c uilabel