title: How to set a default title in UIButton subclass that works in Interface Builder (Xcode 9)
body: <p>I have a button that repeats throughout my app, so I created a subclass to avoid having to set all the basic properties every time.</p>
  
  <p>I am able to set the background colour, the text colour, round the corners.</p>
  
  <p>However, things fall apart when I try to set a default title - something other than "Button".
  In Interface Builder it ignores the title, but it also then ignores the font colour, which works when I don't set the title.</p>
  
  <p>If I run the app, it all looks fine, but one major point of using Interface Builder is to save the step of constantly running the app to check basic UI layout.</p>
  
  <p><a href="https://i.stack.imgur.com/AFytO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AFytO.png" alt="compare Interface Builder with Actual app"></a></p>
  
  <p>Here is the subclass.
  Note that if you comment out the 2 setTitle lines, the button shows the correct text colour (white).</p>
  
  <pre><code>import UIKit
  
  @IBDesignable class ContinueButton: UIButton {
  
      @IBInspectable var titleColour: UIColor = .white {
          didSet {
              setTitleColor(titleColour, for: .normal)
          }
      }
  
      @IBInspectable var bgColour: UIColor = UIColor.gray {
          didSet {
              backgroundColor = bgColour
          }
      }
  
      @IBInspectable var buttonTitle: String = "Continue" {
          didSet {
              setTitle(buttonTitle, for: .normal)
          }
      }
  
      override init(frame: CGRect) {
          super.init(frame: frame)
          setAttributes()
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          setAttributes()
      }
  
      public func setAttributes() {
          setTitleColor(titleColour, for: .normal)
          backgroundColor = bgColour
          setTitle(buttonTitle, for: .normal)
      }
  
      override public func layoutSubviews() {
          super.layoutSubviews()
  
          setAttributes()
  
          layer.cornerRadius = 0.5 * bounds.size.height
          clipsToBounds = true
      }
  }
  </code></pre>
  
  <p>ps, My main objective is to create a reusable custom button that takes care of setting a bunch of defaults. If there's a better way to achieve that, I'd be very happy to hear that - especially if it could be done visually rather than through code.</p>
  
  <p>Thanks for any advice you can give,</p>
  
  <p>-Nico</p>