开发者

iPhone UITextView leaves room for 2 lines at the bottom

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?


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.


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.


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);


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);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜