I am creating an app that creates a UITextView programmatically. The problem is, when the user types in text or the app sets the text, the words spread across one line and off the screen, rather than wrapping to the next line. When I create a UITextView with interface builder, the text wraps automatically, but not when it is created programmatically.
Code:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(100, 12, 210, 60)];
[[self view] addSubview:textView];
[textView becomeFirstResponder];
Available since iOS 7:
textView.textContainer.lineBreakMode = NSLineBreakByWordWrapping;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With