Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing a UITextView to wrap properly

I have a UITextView with the following text:

textView.text = @"aaa a a a a a  a zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";

When I run it in the CGRect that I provided it goes like this:

aaa a a a a a  a 
zzzzzzzzzzzzzzzzzzzzzzz <-text view width ends here
zzzzzzz

But I want it to work like a UILabel with numberOfLines = 0, which gives me this:

aaa a a a a a  a zzzzzz <-text view width ends here
zzzzzzzzzzzzzzzzzzzzzzz <-text view width ends here
z

With iOS 6, UILineBreakMode was deprecated. How do I achieve this now?

like image 692
cdub Avatar asked Jan 23 '15 08:01

cdub


2 Answers

UILineBreakMode is deprecated but not NSLineBreakMode. You should use NSLineBreakByCharWrapping meaning that the word'll be cut after a character.

textView.textContainer.lineBreakMode = .byCharWrapping
like image 68
KIDdAe Avatar answered Nov 18 '22 01:11

KIDdAe


Here is how you can do it in Objective-C

textView.textContainer.lineBreakMode = NSLineBreakByCharWrapping;
like image 33
Pankaj Gaikar Avatar answered Nov 18 '22 01:11

Pankaj Gaikar