iOS Development

Autosizing UITextView, similar to Facebook ‘comment’

I’ve recently had to implement an autosizing text field in a couple different projects, so I decided to put it into a cocoapod, called SBTextInputView. It:

  • uses autolayout, so it should be set for a future versions of iOS and all screen sizes
  • has a translucent background, a UITextView, and a button, all of which are fully customizable
  • can be added directly to your storyboard/xib file or used as an input accessory view.

The trickiest part was making it autosize while being an inputAccessoryView. First it had to add a hidden text field to its super view, and update its height automatically. It was a great opportunity to learn about autolayout and get it working for me instead of against, the way autolayout usually does.

Check it out on GitHub to see how it works; it comes with an example so you can see how easy it is to use. To add it to your project, just include:

pod ‘SBTextInputView’, :git => ‘https://github.com/schrockblock/SBTextInputView

in your Podfile.

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 )

Facebook photo

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

Connecting to %s