I have a String with an URL of GIF banner which I need to put into app.
My code:
func showAdd(){
Request.get("http://www.kyst.no/api/?apiMode=advertisement&lang=no", { (error: NSError?, data: NSData, text: NSString?) -> () in
let jsonResult: Dictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as Dictionary<String, AnyObject>
var banner : NSString = jsonResult["advertisement"]!["banner"] as NSString
self.addViewImage.image = UIImage.animatedImageNamed(banner, duration: 1)
})
}
But nothing happens. Please help.
animatedImageNamed()
doesn't do what you think it does. That method is a shortcut for loading a series of static images that are named like soimage0
,image 1
,image2
and so on and sets them as theanimationImages
array. It does not load an animated image like a GIF. This question has been asked before and has a few answers: https://mcmap.net/q/218618/-display-animated-gif-in-ios -- given it's not Swift, but it shouldn't be difficult to apply the answers to Swift. – StakeoutanimationImages
property. – Stakeout