2014-12-05 139 views
0

我試圖創建一個視圖集合與多個單元格。UICollectionView水平單元格

第一個單元格必須包含時間線。

正如您在圖像中看到的,無法在橫向上打印時間線。

如何水平打印此單元格?

我的代碼:

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

所有細胞水平? – 2014-12-05 11:14:04

+0

不是。共三個單元格,只有兩個水平和一個垂直。在這個鏈接中:你可以看到我在做什麼:http://code4app.net/ios/Static-column-table/50fe649d6803fa7b65000001 – uynva 2014-12-05 11:21:02

+0

減少單元格的大小,這樣兩個單元格將出現在水平寬度中,並在部分中分配三個單元格。 – 2014-12-05 11:23:45

回答

2

默認集合視圖佈局應該已經這樣工作(蘋果文件):

collection view layout

它是如何設置的一年每個單元格。不要使用year++。使它的indexPath.row迴應:

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

還有一個偉大的教程可以在這裏找到:UICollectionView Swift Tutorial

+0

好的,但我希望細胞不包裝線。我想創建一個時間線和水平滾動 – uynva 2014-12-05 11:23:58

+1

好吧,那麼你需要改變UICollectionViewFlowLayout的滾動方向,並將單元格/集合視圖的高度更改爲只允許1行 – Hannes 2014-12-05 11:42:43

+0

如何更改高度細胞 ?我試圖更改故事板,然後單擊CollectionView的單元格大小和我縮小高度。但它不起作用 – uynva 2014-12-05 11:53:35

相關問題