UITextView:获取带有换行信息的文本
是否可以获取 UITextView 中的文本及其换行信息。
在这种情况下。我会收到类似“亲爱的 StackOverFlow,\n\n你让我的...”这样的文本,而不再有“\n”。我想在“and now I”之后得到一个换行符,如 UITextView 中所示。
Is it possible to get the text inside a UITextView with its wrap info.
So in this case. I will get text like "Dear StackOverFlow,\n\nYou make my..." with no more "\n". I would like to get a newline after "and now I", like shown in the UITextView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里查看我的答案:
https://stackoverflow.com/a/13588322/341994
您要求做的正是核心文本为您做什么。事实上,Core Text 是 UITextView 如何知道如何换行的。所以你可以询问 Core Text 换行符在哪里,就像 UITextView 一样。请参阅我的答案中的示例代码 - 它比您想要做的更简单、更可靠。
See my answer here:
https://stackoverflow.com/a/13588322/341994
What you are asking to do is exactly what Core Text does for you. Indeed, Core Text is how UITextView knows how to wrap text. So you can ask Core Text where the line breaks are, just as UITextView does. See the example code in my answer - it's a lot simpler and more reliable than what you're trying to do.
编辑:
马特上面的回答提供了一种更直接的方法来做到这一点。
好吧,看来这是不可能的。我必须手动完成。
这可能不是很准确,我仍在测试错误。
Edit :
Matt's answer above provides a more straight forward way of doing this.
Ok it seems this is not possible. I had to do it manually.
This may not be very accurate and I am still testing for bugs.