Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CollectionView sizeForitemAt method not working for ios 9

I'm having weird issue and I'm not sure why this happening.As you can see this both images one is of ios 9 running ipad and another is ios11 running ipad. for ios9 running ipad cell is not resizing. I search a lot but did't get a answer. Please help me with this and i also attached code. ios9 running Deviceios11 running Device

 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! WalkthroughCollectionViewCell

    let walkObject = walkObjects[indexPath.row]

    cell.walkImageView.image = walkObject.image
    cell.walkHeader.text = walkObject.Header
    cell.walkDetails.text = walkObject.Details
    cell.getStartedButton.addTarget(self, action: #selector(getStarted(sender:)), for: .touchDown)

    if (indexPath.row + 1) == walkObjects.count {
        cell.getStartedButton.isHidden = false
    }else{
        cell.getStartedButton.isHidden = true
    }

    return cell
}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: collectionView.frame.width, height: collectionView.frame.height)
}


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 0.0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 0.0
} 
like image 895
jay patel Avatar asked Dec 13 '17 06:12

jay patel


1 Answers

enter image description here

In my case, I changed Estimate Size from Automatic to None and using:

 collectionView(_ collectionView: UICollectionView, layout
 collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath:
 IndexPath) -> CGSize
like image 199
Senocico Stelian Avatar answered Oct 21 '22 23:10

Senocico Stelian