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
Troubles Using Cgpathcontainspoint Swift
API Violation - Multiple Calls Made to -[Xctestexpectation Fulfill]
How to Select All Text in a Uitextfield Using Swift
What Does "Arg = Exploded" Mean in Swift Crash Log
Running Swift Build in Terminal Leading to "Platform Path" Errors
Swift, Error Exc_Breakpoint (Code=1, Subcode=0X100695474)
How to Open Your App's Settings (Inside the Settings App) with Swift (iOS 11)
Why Are Properties of an Immutable Object Mutable in Swift
How to Detect Text View Begin Editing and End Editing in Swift 3
Behaviour of Protocols with Self
Why Are Objects in the Same Sknode Layer Not Interacting with Each Other
iOS 10 Notification Content Extension Not Loading
Skshapenode Is Not Responding to Physicsbody
Use of Undeclared Type Autoreleasingunsafepointer Xcode 6 Beta 6
Convert Half Precision Float (Bytes) to Float in Swift
Integrate Existing Aws Cognito User Pool into iOS Project with Amplify