您不需要将逻辑放在willDisplay内,而是可以在彩色圆圈内使用UIImageView并在indexPath的基础上隐藏/取消隐藏它。另外,将相机图像放入ImageView中。
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let firstItem:IndexPath = IndexPath(row: 0,section: 0)
if indexPath == firstItem {
coloredCircle.imageView.isHidden = flase
}else{
coloredCircle.imageView.isHidden = true
}
}
,
您可以制作2个不同的单元格。 1个单元格将包含相机视图,其他单元格将包含彩色视图。
在CellforRow方法中,您可以根据需要返回适当的单元格。
如果这不是您想要的,请提前抱歉。因为这是我第一次回答任何问题。 :)
,
请添加这些委托,数据源和FlowLayout委托
UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
为收藏视图创建出口
@IBOutlet weak var currentCollectionView: UICollectionView!
定义单元格的重用标识符
let reuseIdentifier = "actionCell";
为收集视图设置委托和数据源
currentCollectionView.delegate = self
currentCollectionView.dataSource = self
使用重用标识符为收集视图注册单元格
currentCollectionView.register(UINib(nibName: "ActionCollectionViewCell",bundle: nil),forCellWithReuseIdentifier: reuseIdentifier)
UICollectionView委托,数据源和FlowLayoutDelegate的实现
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 4;
}
func collectionView(_ collectionView: UICollectionView,minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 1;
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,for: indexPath) as! ActionCollectionViewCell
cell.vwAction?.layer.cornerRadius = 25.0
cell.vwAction?.clipsToBounds = true
if indexPath.row == 0 {
let imgAction = UIImage(named: "Camera")
cell.imgAction?.image = imgAction
cell.vwAction?.backgroundColor = UIColor.black
} else {
cell.imgAction?.image = nil
cell.vwAction?.backgroundColor = self.randomColor()
}
return cell
}
生成随机颜色的功能
func randomColor() -> UIColor {
let red = CGFloat(drand48())
let green = CGFloat(drand48())
let blue = CGFloat(drand48())
return UIColor(red: red,green: green,blue: blue,alpha: 1.0)
}
ActionCollectionViewCell设计
本文链接:https://www.f2er.com/3140260.html