@IBDesignable not rendering UILabel and UITextField texts

1k Views Asked by At

I've created a @IBDesignable subclass of UIView

The view has couple of labels and a text field.

When I try to change their value in the storyboard, the changes are not rendered. In constant changes in cornerRadius, borderWidth and borderColor are rendered on the storyboard.

What am I missing?

This is how it looks in storyboard:

enter image description here

This is how it looks in the simulator and how I expect it to look in the storyboard after rendering:

enter image description here

This is the code of the class:

import UIKit

@IBDesignable

class LoginTextField: UIView {


    @IBInspectable var cornerRadius: CGFloat = 0 {
        didSet {
            layer.cornerRadius = cornerRadius
            layer.masksToBounds = cornerRadius > 0
        }
    }
    @IBInspectable var borderWidth: CGFloat = 0 {
        didSet {
            layer.borderWidth = borderWidth
        }
    }
    @IBInspectable var borderColor: UIColor? {
        didSet {
            layer.borderColor = borderColor?.cgColor
        }
    }

    @IBInspectable var title: String = "" {
        didSet {
            titleLabel.text = title
        }
    }

    @IBInspectable var placeholder: String = "" {
        didSet {
            textField.placeholder = placeholder
        }
    }

    @IBInspectable var message: String = "" {
        didSet {
            messageLabel.text = message
        }
    }

    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var messageLabel: UILabel!

    @IBOutlet var contentView: UIView!

    override init(frame: CGRect) {

        super.init(frame: frame)
        commonInit()
    }

    override func awakeFromNib() {

        super.awakeFromNib()
    }

    required init?(coder aDecoder: NSCoder) {

        super.init(coder: aDecoder)
        commonInit()
    }

    private func commonInit() {

        let bundle = Bundle.init(for: type(of: self))
        bundle.loadNibNamed("LoginTextField", owner: self, options: nil)
        addSubview(contentView)
        contentView.frame = self.bounds
        contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
    }
}

Update: everything started to work all of a sudden enter image description here

0

There are 0 best solutions below