2017-02-23 29 views
0

我想要做的是在沒有空間的情況下將每個視圖放在下一行。標籤庫正在使用的原理相同(認爲是這樣)。我不希望他們只是滾動到下一行並左對齊。這裏是我的代碼:使用UICollectionView和FlowLayout標籤組件?

self.collection.register(UINib(nibName: "FlowCell", bundle: nil), forCellWithReuseIdentifier: "tag") 
    self.collection.showsHorizontalScrollIndicator = false 
    self.collection.showsVerticalScrollIndicator = false 
    self.collection.dataSource = self 
    self.collection.delegate = self 
    let layout = collection.collectionViewLayout as! UICollectionViewFlowLayout 
    layout.estimatedItemSize = CGSize(width: 10, height: 18) 

這是結果

  1. 有水平滾動方向。這裏我只有一個行:

enter image description here

  • 帶有垂直滾動方向。這裏的內容爲中心,其中:
  • enter image description here

    而這正是我試圖做到:

    enter image description here

    當然,項目的最後一張圖片上的內容是不同的,但如果標籤在同一行上不能多於一個,我希望項目左對齊。

    +0

    嘗試各種不同的文字長度。它是否做同樣的事情? –

    回答