描述->我必须在collectionView的前4行设置4个静态图像,然后我必须在Api的collection视图中设置图像?
有什么建议吗?
func collectionView(_ collectionView:UICollectionView,numberOfItemsSection节:Int(->Int{return DemoImageArrary.count}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
cell.tag = indexPath.row
cell.contentView.layer.cornerRadius = 20
cell.contentView.layer.masksToBounds = true
cell.layer.shadowPath = UIBezierPath(roundedRect:cell.bounds, cornerRadius:cell.contentView.layer.cornerRadius).cgPath
// let Thumnails = DemoImageArrary[indexPath.row]
cell.ThumnailImage.kf.setImage(with: URL(string: DemoImageArrary[indexPath.row]))
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let padding: CGFloat = 20
let collectionViewSize = collectionView.frame.size.width - padding
return CGSize(width: collectionViewSize/2, height: collectionViewSize/2)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 20
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
在UITableView的cellForRowAtIndexpath方法中
写入
if indexPath.row >= 3 {
//indexPath.row gives you the row index
// set image of first four rows like
tableCell.imageView.image = UIImage(named: "(yourLocalImageNamesArray[indexPath.row])")
}else{
// set image from api like
tableCell.YourImageView.image = UIImage(named: "(yourApiImageNamesArray[indexPath.row])")
}