The Finnternet Like the Internet but with more me

Get Swifty: @IBDesignable

One thing that always annoyed me about using custom views was that the storyboard wouldn’t display the customizations I made. This means in order to make sure the textfield’s placeholder text color was right, I would have to build & run my app. This is where the descriptor @IBDesignable comes to the rescue! By adding @IBDesignable on the line above your custom view class & overriding the function prepareForInterfaceBuilder() to run your customizations, storyboard will evaluate & show the customizations made by that class.

@IBDesignable
class MyCustomTextField: UITextField {
    
    override func prepareForInterfaceBuilder() {
        customizeView()
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        
        customizeView()
    }

    func customizeView() {
        // Add customizations here
    }
}