【发布时间】:2021-01-21 09:18:04
【问题描述】:
我想在我的帖子之间添加原生广告,但问题是第二个单元格是“adcell”,使用与“cell”相同的高度,我该如何更改“asdcell”的高度?
这是我的 adcell 代码
collectionView.register(UINib(nibName: "AdViewCell", bundle: nil) , forCellWithReuseIdentifier: "adcell")
collectionView.delegate = self
collectionView.dataSource = self
view.addSubview(collectionView)
并展示广告
let adcell = collectionView.dequeueReusableCell(withReuseIdentifier: "adcell", for: indexPath) as! AdViewCell
if (indexPath.item % 5 == 1){
//admob code here
return adcell
此代码用于设置帖子的高度
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if UIScreen.main.bounds.size.height > 960{ //Write iPhone or iPad size. If iPad :
return CGSize(width: (((collectionView.frame.width) - 40) / 2), height: 500)
} else { //if iPhone
return CGSize(width: view.frame.width-20 , height: 500)
}
}
【问题讨论】:
标签: ios swift uicollectionview cell