如何使用swift将图像字符串值传递给imageslide

时间:2016-12-27 05:30:05

标签: ios json swift image swift2

我正在使用swift 2.2开发一个应用程序,在我的应用程序中使用图片幻灯片,通过引用此链接https://github.com/zvonicek/ImageSlideshow我想传递图像字符串与连接网址....

来自json数据的图像字符串:

{

   "Values Of Image":[{

   "image":"apple.png,jewels.png,gun.png,mango.png"

   }]

}

这只是一个json数据示例,但我正在获取这样的数据

现在我能够分离字符串现在我希望将值传递给alamofire源(imageslide)

在控制器中编码:

在视图中加载:

let MyImageSlide =  json["Values Of Image"][0]["image"].stringValue
        let parts = MyImageSlide.componentsSeparatedByString(",")
        for numbers in parts{
            print("image String:\(numbers)")
         let alamofireSource = [AlamofireSource(urlString: "https://www.something.com" + numbers as String)!]
         self.SecondImageShow.backgroundColor = UIColor.whiteColor()
         self.SecondImageShow.pageControlPosition = PageControlPosition.UnderScrollView
         self.SecondImageShow.pageControl.currentPageIndicatorTintColor = UIColor.lightGrayColor()
         self.SecondImageShow.pageControl.pageIndicatorTintColor = UIColor.blackColor()
         self.SecondImageShow.contentScaleMode = UIViewContentMode.ScaleAspectFill
         self.SecondImageShow.setImageInputs(alamofireSource)
        }

我的回复中的总图像是4 ...但它只获取最后一张图像... 帮我拿取所有图片

1 个答案:

答案 0 :(得分:1)

它只显示最后一个因为你在循环中调用setImageInputs

setImageInputs应该调用图像源数组。您的更改应如下所示。

// create array of image sources
var images = [InputSource]()

for numbers in parts{
     let alamofireSource = AlamofireSource(urlString: "https://www.something.com" + numbers as String)!
    images.append(alamofireSource)
}

self.SecondImageShow.backgroundColor = UIColor.whiteColor()
self.SecondImageShow.pageControlPosition = PageControlPosition.UnderScrollView
self.SecondImageShow.pageControl.currentPageIndicatorTintColor = UIColor.lightGrayColor()
self.SecondImageShow.pageControl.pageIndicatorTintColor = UIColor.blackColor()
self.SecondImageShow.contentScaleMode = UIViewContentMode.ScaleAspectFill

// load the array here
self.SecondImageShow.setImageInputs(images)

请参阅此处的详细课程https://github.com/zvonicek/ImageSlideshow/blob/master/ImageSlideshow/Classes/Core/ImageSlideshow.swift