title: How to add background colour in existing image using Swift?
body: <p>I am trying to add background colour to existing image but it is not working.  </p>
  
  <p>Here below is my code:-  </p>
  
  <pre><code>extension UIImage {
     func imageWithColor(tintColor: UIColor) -&gt; UIImage {
  
      let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
      UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
      tintColor.setFill()
      UIRectFill(rect)
      let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
      UIGraphicsEndImageContext()
  
      //self.type(of: init)(ciImage: CIImage(image: image)!)
      return image
    }
  }
  
  extension UIImage {
  
  /**
   Returns an UIImage with a specified background color.
   - parameter color: The color of the background
   */
  convenience init(withBackground color: UIColor) {
  
      let rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)
      UIGraphicsBeginImageContext(rect.size);
      let context:CGContext = UIGraphicsGetCurrentContext()!;
      context.setFillColor(color.cgColor);
      context.fill(rect)
  
      let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
      UIGraphicsEndImageContext()
  
      self.init(ciImage: CIImage(image: image)!)
  
    }
  }. 
  </code></pre>
  
  <p>I am very new in Graphics and don't know how I can put background colour to an image.</p>
  
  <p>In this white colour image is there and orange colour is background colour.</p>