【发布时间】:2017-04-25 21:06:52
【问题描述】:
美好的一天,我只在 Objective-C 或 Swift 2 中看到过这样的示例,但在运行 Xcode 8 的 Swift 3 中还没有看到。我的情况是我有一个包含一组图像的集合视图,我希望它们是当用户点击它们时放大。这是我的代码:
@IBOutlet weak var collectionView: UICollectionView!
var images = ["catPic1.jpg", "catPic2.jpg", "catPic3.jpg"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
collectionView.delegate = self
collectionView.dataSource = self
} // end of view did load
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return images.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell" , for: indexPath) as! CustomCell
cell.myImage.image = UIImage(named: images[indexPath.row])
return cell
}
顺便说一句,我在另一个 swift 类中有集合视图单元格代码。代码如下:
class CustomCell: UICollectionViewCell {
@IBOutlet weak var myImage: UIImageView!
}
所有图像都正确显示,我只需要在用户选择它们时以某种方式放大它们。谢谢。
【问题讨论】:
标签: ios xcode swift3 uicollectionview