开发者

how can I limit input to 5 lines in a UITextView on iPad?

开发者 https://www.devze.com 2023-04-10 05:25 出处:网络
I have a UITextView in which the user enters lines of text. After the entry of the text I take a screen capture. Problem is, if you enter more than visible lines in textView,开发者_如何学JAVA you can\

I have a UITextView in which the user enters lines of text. After the entry of the text I take a screen capture. Problem is, if you enter more than visible lines in textView,开发者_如何学JAVA you can't screen capture all the text. I tried disabling scrolling, but that makes it worse because text entry from keyboard makes the textview scroll into non-visible area and there's no way for the user to scroll text down again. Thanks in advance for your help.


UITextView is also a ScrollView, so you can use it's contentSize property to only allow text input if the text fits the textView like this:

-(BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    // Only allow text input if the size of the content is smaller than the size of the textView
    return (textView.contentSize.height < textView.bounds.size.height);
}

You will also need to disable the scrolling like you did, to make the UI look good.

0

精彩评论

暂无评论...
验证码 换一张
取 消