0

I have spent 3 days of searching and reading. In my IOS app I have a custom Cell for UICollectionView with xib File. In this custom cell I have 3 labels, images and buttons. 1 label from it is in the middle and always gets different sizes because it's multiline.

So I must calculate all items height. It's not the problem but the problem is only with this one multiline label. So I want calculate the size for each cell and get the size for sizeForItemAtIndexPath in UICollectionViewController.

After 3 days I think I cannot access this. Can I do this from the custom cell class? If yes, how? If I can access it in UICollectionViewController, how?

//MARK: - CollectionView Flow Layout

extension PhotosCollectionViewController: UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        let viewSize = super.view.bounds.size
        let spacing: CGFloat = 0.5
        let width = (viewSize.width) - spacing - 10

        /*
        Here I need my cell with label name "Beschreibungstext"
        to calculate the hight from the label with help from rectangle. 

        return CGSize(width: width, height: customhight)    
        */


    return CGSize(width: width, height: CGFloat(400))

    }

}
dihegroup
  • 21
  • 5

0 Answers0