如果太长,带有滚动视图的 UIlabel 换行符无法正确显示(iPhone 视网膜模拟器)

发布于 2024-12-15 03:53:27 字数 991 浏览 0 评论 0原文

我有 UIlabel 使用下面的代码,我不知道它是否太长。但是当它滚动时, uilabel 会得到这个结果。我该如何解决这个问题?使用 uilabel 有什么限制吗?

图片

CGSize maximumLabelSize = CGSizeMake(100,9999);
CGSize expectedLabelSize = [summaryBlogParsed sizeWithFont: contentSummaryLabel.font 
                                         constrainedToSize:maximumLabelSize 
                                             lineBreakMode: contentSummaryLabel.lineBreakMode]; 

//adjust the label the the new height.
CGRect newFrame = contentSummaryLabel.frame;
newFrame.size.height = expectedLabelSize.height;
contentSummaryLabel.frame = newFrame;
contentSummaryLabel.numberOfLines = 0;
contentSummaryLabel.text = summaryBlogParsed;

[contentSummaryLabel sizeToFit];
contentScrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*2 + CGRectGetMaxY(contentSummaryLabel.frame));

编辑: 当我使用 Iphone Retina 模拟器时会出现此问题。

i have UIlabel using below code, i don't know maybe its too long or not. but when it is scrolled, the uilabel get this result. How can i solve the problem? are there any limitation using uilabel?

Picture

CGSize maximumLabelSize = CGSizeMake(100,9999);
CGSize expectedLabelSize = [summaryBlogParsed sizeWithFont: contentSummaryLabel.font 
                                         constrainedToSize:maximumLabelSize 
                                             lineBreakMode: contentSummaryLabel.lineBreakMode]; 

//adjust the label the the new height.
CGRect newFrame = contentSummaryLabel.frame;
newFrame.size.height = expectedLabelSize.height;
contentSummaryLabel.frame = newFrame;
contentSummaryLabel.numberOfLines = 0;
contentSummaryLabel.text = summaryBlogParsed;

[contentSummaryLabel sizeToFit];
contentScrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*2 + CGRectGetMaxY(contentSummaryLabel.frame));

Edit:
This problem occur when i use Iphone Retina simulator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抽个烟儿 2024-12-22 03:53:27

它看起来就像标签相互叠加。您可以尝试将其 backgroundColour 设置为 [UIColor clearColor] 并将其 opaque 属性设置为 NO 以检查它是否是确实如此。如果是,那么您将必须检查您的框架设置代码。

如果整个内容是一个标签,那么您可能不希望单个标签包含这么多行,但您可以尝试调用 setNeedsDisplay 来强制重绘。

It looks like labels overlaying on top of each other. You can try setting their backgroundColour to [UIColor clearColor] and their opaque property to NO to check that it is indeed the case. If it is then you will have to check your frame setting code.

If the whole thing is one label then you probably don't want a single label with so many lines, but you can try calling setNeedsDisplay to force redrawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文