swift - 我在 TableViewCells 中有 CollectionView 单元格。我在根据不同的模拟器调整 UIImageView 宽度时遇到问题
问题描述
我在集合视图布局函数 sizeForItemAt 中使用了 CGSize(width: 370, height: 240),它不是动态的。宽度:370 非常适合 iPhone 12/Pro,但不适用于其他手机壳。因此我得到以下输出:- iPhone Mini Simulator
我在文件中的扩展名是:
extension EventAttendTableCell : UICollectionViewDelegateFlowLayout,UICollectionViewDelegate,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
eventAttendArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionViewEventAttend.dequeueReusableCell(withReuseIdentifier: "EventAttendCollectionCell", for: indexPath) as? EventAttendCollectionCell else {fatalError("Error to create TableViewCell")}
let attendData = eventAttendArray[indexPath.row]
cell.imgAttend.image = UIImage(named: attendData.imgEventAttendModel)
cell.lblAttend1.text = attendData.lblEventAttendModelTop
cell.lblAttend2.text = attendData.lblEventAttendModelMiddle
cell.lblAttend3.text = attendData.lblEventAttendModelBottom
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
20
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
20
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 370, height: 240)
}
}
“eventAttendArray”是模型文件中的数据数组。
解决方案
推荐阅读
- azure - Azure 加入 AD 在 Windows 10 中失败
- kubernetes - 就绪探针健康后 K8S 滚动更新关闭 pod
- javascript - 在 Typescript 中的类之间进行通信
- android - Firebase 实时数据库快速删除大查询结果
- html - 为什么是将用户选择设置为无后被选中?
- sql - 通过使用火花数据框进行分组时获取具有条件的列的第一个值
- omnet++ - 如何在 UDPBAsicApp 消息中获得基于 INET 的 WirelessHost 速度?
- javascript - React npm start 导致 react web app 从任何目录启动同一个项目(即使该项目被删除)
- debugging - 为什么我在模拟器中运行代码时在调试区域看不到打印语句?
- networking - 为什么我们在 IPv4 地址中没有区域 ID(例如在 % 字符之后的 IPv6 地址)?