Self Sizing CollectionViewCell

时间:2016-07-26 05:43:39

标签: ios objective-c iphone uitableview uicollectionview

我尝试根据内容制作我的collectionView Cell高度。 我尝试使用Self Sizing CollectionViewCell,但它无法正常工作。 我在CollectionView Cell中使用了自动布局。

单元格有三个标签top,left,bottom,right Constraints&需要垂直压缩比率(1000)。

我的代码如下:

override func viewDidLoad() {
    super.viewDidLoad()
    let flowlayout = col.collectionViewLayout as! UICollectionViewFlowLayout
   flowlayout.estimatedItemSize = CGSizeMake((self.view.frame.size.width - 60) / 2 , 1)
    }
}


//MARK: CollectionView

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

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

    let cell = col.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CustomCell

    if indexPath.row == 0 {
        cell.lbl1.text = "Lorem ispum Simple text to show if it working or not"
    }
    else{
        cell.lbl1.text = "\(indexPath.row)"
    }       
    return cell
}

有些人说即使Apple声称它也不可能使用collectionView Self Sizing Cell。 您必须手动计算。

如果我尝试手动计算,那么我也无法在sizeForItemIndexPath中获取单元格对象

0 个答案:

没有答案
相关问题