0

I have a UITextView that has maxLines set like this:

textView.textContainer.maximumNumberOfLines = 3; textView.textContainer.lineBreakMode = .byTruncatingTail textView.isScrollEnabled = false 

However, when typing in the textView, you can press return several times and type beyond 3 lines. Visually, only 3 lines appear, but as you type text is being entered on and on. Is there a way to prevent this?

1

2 Answers 2

0

The maximum number of lines is used to define how many will be visible in the interface. This has nothing to do with the amount of text you type.

If you want to add a "limit" to the number of characters you have to do it programmatically.

There are several other answers related to this on SO.

How to limit characters in UITextView iOS

Sign up to request clarification or add additional context in comments.

2 Comments

I found how to limit the number of characters, but not how to limit the number of lines. Which is why I asked if this was possible with the UITextView itself.
No it's not possible with just the UITextView itself, it has to be done programmatically as well.
0

You can try this

textView.textContainer.maximumNumberOfLines = 3 textView.textContainer.lineBreakMode = .byTruncatingTail textView.layoutManager.textContainerChangedGeometry(textView.textContainer) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.