UIScrollView图像未加载

时间:2018-04-11 22:07:52

标签: ios swift uiscrollview

我正在使用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
}

1 个答案:

答案 0 :(得分:0)

imageArray是一个UIImage - s而不是String -s的数组,您应该直接分配图像

cell.imageView?.image =  self.imageArray[index]

UIImage(named用于从主Bundle

加载具有该名称的图像
let image = UIImage(named:"imageName.png")