title: Adding and changing a custom UIView programmatically (Swift)
body: <p>I am trying to create a custom UIView that I can use in my other UIViewControllers.</p>
  
  <p>The custom view:</p>
  
  <pre><code>import UIKit
  
  class customView: UIView {
  
      override init(frame: CGRect) {
  
          super.init(frame:frame)
  
          let myLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 250, height: 100))
          addSubview(myLabel)
      }
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
      }
  }
  </code></pre>
  
  <p>Then I want to add it in to a separate UIViewController:</p>
  
  <pre><code>let newView = customView(frame:CGRectMake(0, 0, 500, 400))
  self.view.addSubview(newView)
  </code></pre>
  
  <p>This works to display the view, but what do I need to add to be able to change the properties (such as myLabel) from the UIViewController that is embedding the customView?</p>
  
  <p>I'd like to be able to access and change the label from the viewController, allowing me to change text, alpha, font, or hide the label using dot notation:</p>
  
  <pre><code>newView.myLabel.text = "changed label!"
  </code></pre>
  
  <p>Trying to access the label now gives the error "Value of type 'customView' has no member 'myLabel'"</p>
  
  <p>Thanks so much for any help!</p>