swift - 试图快速生成布局
问题描述
我正在尝试快速生成布局。它将动态生成。而且我添加了布局输出,但第三个框必须低于第二个框。第一个和第四个框必须保持不变。
import UIKit
class ViewController: UIViewController {
var cellIds = ["1","2","3","4","5","6"]
let cellSizes = [
CGSize(width:190, height:300),
CGSize(width:190, height:150),
CGSize(width:190, height:150),
CGSize(width:400, height:150),
CGSize(width:190, height:100),
CGSize(width:190, height:100),
]
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cellIds.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MenuCell", for: indexPath) as? UICustomCollectionViewCell
cell!.layer.cornerRadius=10
cell!.layer.masksToBounds=true
return cell ?? UICollectionViewCell()
}
}
extension ViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return cellSizes[indexPath.item]
}
}
解决方案
推荐阅读
- java - 单击按钮时如何更改 Firestore 查询?
- javascript - dash.js 多次重新加载同一段
- r - 通过查找另一个数据框在 R 中创建一个新列
- ruby - Ruby:评估顺序取决于空格和看似多余的括号,为什么?
- reactjs - react-intl 包中 defineMessages 的打字稿
- android - 我如何为大用户群的 android 应用程序登录服务器?
- android - 通知父小部件在异步子小部件中加载数据时发生错误
- c# - 如何解决 BlazorServer 默认项目解决方案中的命名空间错误(VisualStudio 代码)
- c - 我不知道为什么在 pthread 子例程中更改变量访问/存储类型会大幅提高性能
- hadoop - 我试图运行纱线,但遇到了这个问题。纱线已安装但甚至无法访问该版本