How to Pass Image Value to The Imageslideshow Using Swift

How to pass image string value to the imageslide using swift

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

How to pass image value to the ImageSlideshow using Swift

Let try this to add SDWebImage to ImageSlideshow

Create outlet for your slideshow

@IBOutlet var slideshow: ImageSlideshow!

With your Example :

var imageSDWebImageSrc = [SDWebImageSource]()

let url="https://myoscapp.com/boot/json_procuct_info.php"
Alamofire.request(url, method: .get).validate().responseJSON { response in
switch response.result {
case .success(let value):
let json = JSON(value)
let imageslider = json[0]["products_gallery"].array
if json[0]["products_gallery"].array != nil {
for url in imageslider{
let image = SDWebImageSource(urlString: url)
if let sdURL = image{
imageSDWebImageSrc.append(sdURL)
}
}
self.slideshow.setImageInputs(self.imageSDWebImageSrc)
}
}
}

in Addition:

How to set ImageSlideshow image sources for ImageSource, SDWebImage, AFURLSource, AlamofireSource, KingfisherSource.

Update:
You have to install it.

pod "ImageSlideshow/SDWebImage"

Run pod install

iOS: Set setImageInputs of image slideshow to array of images

you should try this way for sure, because you reset inputs in your for-loop

var imageSource: [ImageSource] = []
for image in self.iconArr {
let img = image
imageSource.append(ImageSource(image: img))
}
self.SlideShow.setImageInputs(imageSource)

As sooper stated, can be done this way

let imageSources = self.iconArr.map { ImageSource(image: $0) } 

Passing dynamic array to ImageSlideshow ios

try this :

let arr =  jsonArray.map { AFURLSource(urlString: $0 as! String)!}
slideShow.setImageInputs(arr)

hope it be helpful :-)

Append UI Images from array to slideshow swift

You have pass to self.slider.setImageInputs array of all objects ImageSource [ImageSource(image: self.testimg1), ImageSource(image: self.testimg2), ...] etc., not only one object [ImageSource(image: self.testimg)].

If you add images like:

self.slider.setImageInputs([ImageSource(image: self.testimg)])
self.slider.setImageInputs([ImageSource(image: self.testimg2)])
you'll simply replace first image with second.

Create new array, enumerate all images from sliderArray, and append they to array ImageSource(image: self.testimg1) objects.

Also remember, you have to call this from block glrimg.getDataInBackgroundWithBlock!

add before for

var count = 0

and add inside block

count +=1
if count == objects.count {
print(self.sliderArray)
}.

That will print array when all objects finished loads (they can loads in chaotic order).

passing all members of a json array from an API call in swift

You can try

var allImages = [SDWebImageSource]()
if let allStr = ProductServices.instance.selectedProduct?.productImg {
for str in allStr {
allImages.append(SDWebImageSource(urlString:str))
}
}

if allImages.isEmpty {
// display custom image // or add it's default str
}

NSTimer Issues to start image slideshow automatically

The timer's target selector is the function that gets called on the interval that you specify. In the code above, you're using the getter for your slider property as the function for the timer to call-- that's not doing what you want. The timer is going to call that getter every 5 seconds, but all that getter function does is just "get" the value of the slider property.

You want the timer's selector to do something for you, for example, to trigger the "next" button function. Why not use the form of timer creation that allows you to specify a closure to wrap the behavior? Something like:

time = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
self.NextButton(self)
}

(This seems more elegant in Swift than using a #selector to point to an objc exposed function anyway.)

how to pass [String]' to 'String' value in swift

Essentially, what you are trying to do is to transform each element of a [String] to a SDWebImageSource, so that it forms a [SDWebImageSource]. Right? This is precisely the job of the map method.

let imageSource = self.myArray.map { SDWebImageSource(urlString: $0) }

Or more simply:

let imageSource = self.myArray.map(SDWebImageSource.init))


Related Topics



Leave a reply



Submit