在IOS7中使用UITextView的sizetofit时会发生奇怪的事情 [英] Weird thing occurs when using sizetofit of a UITextView in IOS7

查看:128
本文介绍了在IOS7中使用UITextView的sizetofit时会发生奇怪的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在IOS7模拟器上测试我的应用程序时。
有时我发现当我使用 sizeToFit UITextView 时,这很奇怪。
sizeToFit 之后的框架似乎正确,但文本只能部分显示如下图所示。 (灰色区域代表 UITextView sizeToFit 之后的新框架,整个句子应该是引发了紧张关系两个。)

When I test my app on IOS7 simulator. Sometimes I found it is weird when I using sizeToFit of a UITextView. The frame after sizeToFit seems right but the text can only show partly just like the photo below. (The gray area represents the UITextView new frame after sizeToFit, the whole sentence should be "which sparked a tense relationship between the two.")

UITextView 文本是通过attributedText设置的。
似乎问题只出现在一些句子中,大多数句子都可以。

The UITextView text is set via attributedText. It seems the problem occurs with some sentences only and is OK for most sentences.

我多次遇到这个问题,但还是无法解决。
任何帮助将不胜感激。谢谢。

I met this problem several times and can not solve it yet. Any help will be appreciated. Thanks.

更新:

最后我以丑陋的方式解决问题。我重置了textView的文本。

Finally I solve the problem in an ugly way. I reset the text of the textView.

NSString *text = textView.text;
textView.text = @"";
textView.text = text;

现在它可以在sizeToFit之后显示整个内容。
我认为这似乎是IOS 7的错误。

Now it can show the whole content after sizeToFit. I think it seems like a IOS 7's bug.

推荐答案

我遇到了同样的问题,我花了一段时间要搞清楚,你只需要调整文本容器的大小

I had the same problem, it took me a while to figure it out, you simply need to resize the text container

[textview sizeToFit];
[textview.textContainer setSize:textview.frame.size];

这篇关于在IOS7中使用UITextView的sizetofit时会发生奇怪的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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