我正在使用here的图片幻灯片:

    iconArr = [UIImage(named: "home-min")!,UIImage(named: "category-
   min")!,UIImage(named: "settings-min")!,UIImage(named: "contact us-min")!,UIImage(named: "about us-min")!,UIImage(named: "logout")!]

我需要将此数组作为图像源。
for image in self.iconArr {
            let img = image
            self.SlideShow.setImageInputs([ImageSource(image:  img)])
             }

但这不起作用,我该怎么办?

最佳答案

您应该确定尝试这种方式,因为您重置了for-loop中的输入

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

正如索珀所说,可以通过这种方式完成
let imageSources = self.iconArr.map { ImageSource(image: $0) }

10-08 01:28