Question: How to pass image string value to the imageslide using swift

Question

How to pass image string value to the imageslide using swift

Answers 1
Added at 2016-12-27 06:12
Tags
Question

I am developing a app using swift 2.2 in my app am using image slide show by refering this link https://github.com/zvonicek/ImageSlideshow i want to pass images string with concatenating url....

images string am getting from the json data:

{

   "Values Of Image":[{

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

   }]

}

this is just an example json data but am getting data like this

now i can able to seperate the string now i want pass the value to alamofire source(imageslide)

coding in controller:

in view did load:

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)
        }

total images in my response is four...but it fetches last image only... help me to fetch all the images

Answers to

How to pass image string value to the imageslide using swift

nr: #1 dodano: 2016-12-27 07:12

It only show the last because you call the setImageInputs inside the loop.

setImageInputs should call the array of image source. Your changes should be something like below.

// 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)

Refer the detail class here https://github.com/zvonicek/ImageSlideshow/blob/master/ImageSlideshow/Classes/Core/ImageSlideshow.swift

Source Show
◀ Wstecz