Search code examples
objective-chyphenationword-break

How can I justify the text or make it stop separating the words in a UITextview?


I have an application with a chat, which the design is made with code in objective-c, but in the dialogues the words are broken. How can I justify the text or do a kind of word wrap for the UItextview?

This is an image of what I'm talking about https://serving.photos.photobox.com/5690512502fd6b9b94cda7ff55dae480af40b3eaf5d952204e938af42be59226a480c160.jpg

I added a HypherationFactor of 1 but the problem is not solved, just fix some. I've been trying for a while and I can not do it.

_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;

I want the words to be understood; for example: tempera- ture


Solution

  • You Just need to add one line code in your textView code.

    textView.textContainer.lineBreakMode = NSLineBreakByWordWrapping;