title: How to add gradient layer which fills the view frame exactly
body: <p>In my app i'm adding the gradient layer to UIView and UIToolBar but it doesn't fill the views exactly 
  <a href="https://i.stack.imgur.com/qSWeS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qSWeS.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/FyhIm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FyhIm.png" alt="enter image description here"></a></p>
  
  <pre><code>    let gradient:CAGradientLayer = CAGradientLayer()
      gradient.frame               =  self.vw_gradientForToolBar.bounds
      gradient.colors              = [hexStringToUIColor(hex: "#5d8f32").cgColor,hexStringToUIColor(hex: "#04667f").cgColor]
      gradient.startPoint = CGPoint(x: 0, y: 0)
      gradient.endPoint = CGPoint(x: 0.5, y: 0)
  
      UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), false, 0.0)
      let img : UIImage = UIGraphicsGetImageFromCurrentImageContext()!
      UIGraphicsEndImageContext()
      self.toolBar.setBackgroundImage(img, forToolbarPosition: .any, barMetrics: .default)
      vw_gradientForToolBar.layer.addSublayer(gradient)
  </code></pre>
  
  <p>View Hirarchy</p>
  
  <p><a href="https://i.stack.imgur.com/wlrGI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wlrGI.png" alt="enter image description here"></a></p>
  
  <p>enter image description here</p>