title: Creating subviews in UIView subclass in swift
body: <p>i have this code for the <code>UIView</code> subclass.</p>
  
  <pre><code>import UIKit
  
  class DrawingSquareView: UIView {
  
  
      override func drawRect(rect: CGRect)
        {
          var apertureRect : CGRect = CGRectMake(80, 200, 160 , 158)
          var context : CGContextRef = UIGraphicsGetCurrentContext()
  
              /* draw the transparent rect */
          CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0)
          CGContextSetBlendMode(context, kCGBlendModeCopy)
          CGContextFillRect(context, apertureRect)
  
      //        /* draw a white border */
          CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0)
          CGContextStrokeRect(context, apertureRect)
       }
      override func awakeFromNib()
      {
      var cropButtons : UIButton = UIButton(frame: CGRectMake(70, 150, 160 , 158))
      cropButtons.setTitle("Crop Image", forState: UIControlState.Normal)
      cropButtons.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
      self.addSubview(cropButtons)
  
      }
      init(frame: CGRect)
      {
          super.init(frame: frame)
      }
  
       override func hitTest(point: CGPoint, withEvent event: UIEvent!) -&gt; UIView!
       {
          var view : UIView = self.superview
          return view.viewWithTag(99)
  
      }
     }
  </code></pre>
  
  <p>and also this code for calling the UIView subclass in the UIViewController class</p>
  
  <pre><code>@IBAction func CropButtonClicked(sender: UIButton)
      {
          var DrawingSquareObject : DrawingSquareView = DrawingSquareView(frame:self.view.frame)
          self.view.addSubview(DrawingSquareObject)
     }
  </code></pre>
  
  <p>but when I click in the button in the <code>superview</code> , it does showing the rectangle that I created in the <code>UIView</code> subclass by using the <code>draRect:</code> , But it showing the UIButton that I created in the  <code>awakefromNib()</code>. I tried adding the subview in the <code>init(frame:)</code>, <code>init(coder:)</code>, <code>addsubview(view:)</code> functions, none of them show the <code>UIButton</code>. Also I want to know how can I remove this <code>DrawingSquareView</code> from the <code>superview</code>.</p>
  
  <p>Please help me , Thank you in advance.</p>