iOS: Reusable gradient view with title in Interface Builder
This blog post will describe how to build a reusable gradient view, with a title using @IBDesignable and Interface Builder.
Why do this? If a view component is reused throughout the app, it’s easier to write it once and reuse the component. It aids the design process to see these view components rendered as they appear in the running app, and it makes changing the design much less painful.
Here’s what the final result looks like:
There are two key components, an @IBInspectable title that connects to a UILabel, and a CAGradientLayer:
Next, let’s use the class in Interface Builder:
And configure it:
If the view is not rendered in Interface Builder, in the menu:
Editor -> Refresh All Views
That’s it! For more Interface Builder examples, check out this post about building an underlined Material Design text field.