【问题标题】:How can I justify the text or make it stop separating the words in a UITextview?如何证明文本的合理性或使其停止分隔 UITextview 中的单词?
【发布时间】:2018-12-21 19:06:50
【问题描述】:

我有一个带有聊天功能的应用程序,它的设计是用 Objective-c 中的代码制作的,但是在对话中单词被破坏了。如何证明文本的合理性或为 UItextview 做某种自动换行?

这是我正在谈论的图像 https://serving.photos.photobox.com/5690512502fd6b9b94cda7ff55dae480af40b3eaf5d952204e938af42be59226a480c160.jpg

我添加了一个 1 的 HypherationFactor,但问题没有解决,只是修复一些。我已经尝试了一段时间,但我无法做到。

_textView=[[UITextView alloc] init];
[_textView setTextContainerInset:UIEdgeInsetsZero];
_textView.textContainer.lineFragmentPadding = 0;
_textView.dataDetectorTypes=UIDataDetectorTypeAll;
_textView.font=[UIFont systemFontOfSize:17]; 
_textView.textColor=kTextColor;
_textView.layoutManager.hyphenationFactor = 1;
_textView.backgroundColor=[UIColor clearColor];
_textView.scrollEnabled=NO;
_textView.editable=NO;

我希望这些话被理解;例如:温度- 真的

【问题讨论】:

  • 您好 Esteban,欢迎来到 StackOverflow。我已将您的代码复制并粘贴到一个测试项目中,仅向 _textview 和一些文本添加了一个框架,并且通过按音节截断单词,它可以按您的预期工作。你确定你没有在代码的其他地方搞乱它的换行管理吗?

标签: objective-c hyphenation word-break


【解决方案1】:

你只需要在你的 textView 代码中添加一行代码。

textView.textContainer.lineBreakMode = NSLineBreakByWordWrapping;

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    • 2020-12-29
    相关资源
    最近更新 更多