Loading/Downloading image from URL on Swift

前端 未结 30 3159
感动是毒
感动是毒 2020-11-21 05:39

I\'d like to load an image from a URL in my application, so I first tried with Objective-C and it worked, however, with Swift, I\'ve a compilation error:

30条回答
  •  没有蜡笔的小新
    2020-11-21 06:13

    You can use pod SDWebImage to achieve the same. Its easy to use. Yo can get documentaion here SDWebImage

    Here is the sample code

    self.yourImage.sd_setImage(with: NSURL(string: StrUrl as String ) as URL!, placeholderImage: placeholderImage, options: SDWebImageOptions(rawValue: 0), completed: { (image, error, cacheType, imageURL) in
                    if( error != nil)
                    {
                        print("Error while displaying image" , (error?.localizedDescription)! as String)
                    }
                })
    

提交回复
热议问题