Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView水平单元_Ios_Swift_Uicollectionview - Fatal编程技术网

Ios UICollectionView水平单元

Ios UICollectionView水平单元,ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我正在尝试创建包含多个单元格的视图集合 第一个单元格必须包含时间线 如图所示,无法水平打印时间线 如何水平打印此单元格? 我的代码: class ViewController: UIViewController, UICollectionViewDataSource,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { var year = 2000 override func viewDidLoad()

我正在尝试创建包含多个单元格的视图集合

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

如图所示,无法水平打印时间线

如何水平打印此单元格?

我的代码:

      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
    }
}

默认的集合视图布局应该已经是这样(来自Apple Docs):

这是你为每个细胞设定年份的方式。不要为此使用
year++
。使其响应
indexPath.row

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

这里还有一个很好的教程:

所有单元格都是水平的?不太好。总共三个单元格,只有两个水平单元格和一个垂直单元格。在此链接中:您可以看到我所做的:减小单元格大小,使两个单元格水平宽度。并在节中指定三个单元格。noOfYears/3应该是您的节。很抱歉,我不理解。为什么要缩小单元格大小?我只是希望单元格在水平行中一个接一个地打印,但我希望单元格不包线。我想创建一条时间线并随水平滚动移动OK,然后您需要更改UICollectionViewFlowLayout的滚动方向,并更改单元格/集合视图的高度,以仅允许1行。我如何更改单元格的高度?我尝试过改变故事板,然后点击CollectionView cellsize,我降低了高度。但它不起作用您应该实现UICollectionViewDelegateFlowLayout,并在collectionView:layout:SizeFormiteIndeXPath:(请参见此处:)中提供正确的大小,但不需要实现方法:SizeFormiteIndeXPath。项目的大小也可以从情节提要中更改。但我不明白为什么改变大小应该打印在一行