Search code examples
iosswiftviewbackground-image

How to set background image to the view using URL in swift


I am developing a app using swift 2.2 in my app I need to add a background image to the view which am getting from the URL I know how to add to imageview but I can't add to view.


Solution

  • Alamofire.download("https://httpbin.org/image/png").responseData { response in
        if let data = response.result.value {
            let image = UIImage(data: data)
            self.view.backgroundColor = UIColor.init(patternImage: UIImage.init(CGImage: image.CGImage!))
    
        }
    }