title: Using IBDesignable and prepareForInterfaceBuilder with a UILabel
body: <p>I have a subclass of <code>UIView</code> called <code>MyView</code> that I am creating.</p>
  
  <p>In it there is a <code>UILabel</code> (this is added in code not in InterfaceBuilder for reasons).</p>
  
  <p>I then have a property on <code>MyView</code> called <code>color</code>.</p>
  
  <p>What I'd like is to have Interface Builder be able to select the <code>color</code> and also to then display the label with the font set to that color.</p>
  
  <p>In my code I have...</p>
  
  <pre><code>@IBDesignable class MyView: UIView {
  
      private let textLabel = UILabel()
  
      @IBInspectable var color: UIColor = .blackColor() {
          didSet {
              textLabel.textColor = color
          }
      }
  
      required init(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
  
          initialSetup()
      }
  
      override init(frame: CGRect) {
          super.init(frame: frame)
  
         initialSetup()
      }
  
      private func initialSetup() -&gt; Void {
          self.backgroundColor = .clearColor()
  
          textLabel.textAlignment = .Center
          textLabel.numberOfLines = 0
  
          addSubview(textLabel)
      }
  
      override func layoutSubviews() {
          super.layoutSubviews()
  
          textLabel.frame = bounds
      }
  
      // I have no idea what I'm doing here?!
      override func prepareForInterfaceBuilder() {
          // should I create a label specifically for here?
          // or should I use the property textLabel?
  
          textLabel.text = "Hello, world!" // setting place holder IB text?
          textLabel.textColor = color
          textLabel.font = .systemFontOfSize(21)
          textLabel.textAlignment = .Center
          textLabel.numberOfLines = 0
  
          // do I need to add sub view?
      }
  
  }
  </code></pre>
  
  <p><strong>IBInspectable</strong></p>
  
  <p>In IB I can see the color property there and I can set it. Annoyingly it takes a default value of .clearColor() though not the color I set in code. Is there a way to fix that?</p>
  
  <p><strong>IBDesignable</strong></p>
  
  <p>When I put the view into InterfaceBuilder it shows all the inspectable properties but nothing is shown in the actual view.</p>
  
  <p>When I run it it all works fine. I'd just like to be able to get something working (other than drawRect) in IB. I'm finding a distinct lack of documentation though.</p>
  
  <p><strong>Edit - Warnings</strong></p>
  
  <p>I just noticed that I'm getting build errors / warnings saying...</p>
  
  <blockquote>
    <p>warning: IB Designables: Ignoring user defined runtime attribute for key path "color" on instance of "UIView". Hit an exception when attempting to set its value: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key color.</p>
  </blockquote>
  
  <p>This will probably change the solution :)</p>