Add a height-flexible placeholder to your UITextView

Add a height-flexible placeholder to your UITextView
Photo by Nick Adams / Unsplash

Once you have tasted SwiftUI, this kind of UIKit lacking makes you wish you could refactor a client's whole codebase at a snap from your fingers. At least the UI side of it. But, alas, there is no magic spell for that. Yet.

What kind of lacking? UITextView doesn't have a placeholder property, and no sensible way of setting one up is provided.

So, how do we do it? While some would suggest setting the UITextView's text property to your desired placeholder, add changing the text's style back and forth, I prefer the floating placeholder approach. Mainly because I prefer something self-contained and easily reusable.

So, let's make just that, shall we?