Load image from url

  1. 2 years ago
    Edited 2 years ago by niutech

    Hi. I am currently loading images into UIImage that are stored in app. I would prefer to load them from my website. I am a beginner and have managed to get the following code to work but cannot find any tutorials that can help me to change it to loading from url.
    Here is the code so far

    @IBAction func btn1(sender: AnyObject) {
            let combo = self.txt1.text! + self.txt2.text! + ".png"
            imgdisp.image = UIImage(named: combo)
        }

  2. niutech

    20 Jan 2016 Administrator

    You can do it like this:

    let url = NSURL(string: combo)
    let data = NSData(contentsOfURL: url!)
    imgdisp.image = UIImage(data: data!)

or Sign Up to reply!