iPhone UITextView leaves room for 2 lines at the bottom

こ雲淡風輕ζ 提交于 2020-01-05 05:56:30

问题


When I start typing text in a default textView in my viewcontroller, it's not going to the bottom of the textfield. It leaves room for 2 more lines of text and then starts scrolling. I want it to start scrolling when I start going beyond the last line.

I tried everything, and I don't know what I can do? Anyone any ideas?


回答1:


as UITextView is a subclass of UIScrollView, look at UIScrollVIew's properties, like contentInset and others to see if they might be creating a gap between your frame/bounds and the content inside.




回答2:


Just adding to what mahboudz already said. Here's some sample code that can be adjusted to get what you need:

    UIEdgeInsets contentInset = notes.contentInset;
    contentInset.bottom = 10.0;
    notes.contentInset = contentInset;

Where notes in this example is the UITextView.




回答3:


In addition to what mahboudz and Aaron said, I can confirm that UITextView does add some contentInset to the bottom, so I put the following code inside textView:shouldChangeTextInRange:replacementText: of UITextViewDelegate

textView.contentInset = UIEdgeInsetsMake(0, 0, 5, 0);



回答4:


When moving code from a nib to setting it up programmatically, I ran into a similar problem--wherever the insertion point was, it was scrolled up out of view. I eventually found that my UITextView had a bottom inset of 32 pixels when I created it programmatically, though I'm not sure why. So I fixed it by setting the contentInset when I create the text view:

textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);


来源:https://stackoverflow.com/questions/1582554/iphone-uitextview-leaves-room-for-2-lines-at-the-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!