我正在使用FSPagerView创建一个包含多个图像的优雅UIScrolView。我试图关注documentation,但是在尝试从imagesArray加载图像时出现错误。 error
var imageArray = [UIImage(named: "LA"),UIImage(named: "SF"), UIImage(named: "NY"), UIImage(named: "Miami"), UIImage(named: "LasVegas"), UIImage(named: "Chicago")]
@IBOutlet weak var pagerView: FSPagerView!{
didSet{
self.pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
}
}
public func numberOfItems(in pagerView: FSPagerView) -> Int {
return imageArray.count
}
public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
cell.imageView?.image = UIImage(named: self.imageArray[index])
return cell
}
答案 0 :(得分:0)
imageArray
是一个UIImage
- s而不是String
-s的数组,您应该直接分配图像
cell.imageView?.image = self.imageArray[index]
此UIImage(named
用于从主Bundle
let image = UIImage(named:"imageName.png")