gpt4 book ai didi

ios - UICollectionView 水平单元格

转载 作者:行者123 更新时间:2023-11-28 13:19:03 25 4
gpt4 key购买 nike

我正在尝试创建一个包含多个单元格的 View 集合。

第一个单元格必须包含时间线。

正如您在图像中看到的那样,无法水平打印时间线。

如何水平打印此单元格?

我的代码:

      class ViewController: UIViewController, UICollectionViewDataSource,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
var year = 2000
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 200
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: 97, height: 33)

}


func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as MyViewCell

cell.textView.text = "\(year)";
year++;

return cell
}
}

最佳答案

默认的 Collection View 布局应该已经像这样工作了(来自 Apple Docs):

collection view layout

这就是您为每个单元格设置年份的方式。不要为此使用 year++。让它响应 indexPath.row:

cell.textView.text = "\(2000 + indexPath.row)";

这里还有一个很棒的教程:UICollectionView Swift Tutorial

关于ios - UICollectionView 水平单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27314537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com