Home > iOS SDK > Single line UITextView

Single line UITextView

The standard behaviour of the UITextView automatically resets the contentInset property to 32, which causes strange behaviour if you just want an UITextView with a single line. On responding the cursor disappears in the negative content area. The solution is simple. Just subclass the UITextView and force overwrite the property contentInset with UIEdgeInsetsZero. It just acts like an UITextField now. The SMS.app for example uses this behaviour for text-input with the ability to enter multiple lines.


@interface InputTextView : UITextView
@end

@implementation InputTextView

/*************************************************
* fixes the issue with single lined uitextview
*************************************************/
- (UIEdgeInsets) contentInset { return UIEdgeInsetsZero; }

@end
About these ads
Categories: iOS SDK Tags:
  1. kusmi
    June 15, 2010 at 8:39 pm

    This ist correct, but watch out – Apple did this on purpose. If you remove this inset, then the “word-tip” or correction bubble will be cut by the bounds of the UITextview. You can then set clipToBounds=NO, but then you can’t activate the dismiss x anymore…

    So you see, there is a whole chain reaction started here :-)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: