0

How to make content offset of collection view cell. Code below what do I have but It doesn't work for some reason:

  override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "pCell", for: indexPath) as! CollectionViewCell
    cell.imageView.image = UIImage(named: "1")!

    cell.offset(offset: CGPoint(x: 0.0, y: -30.0))

    return cell
  }

My cell class code:

class CollectionViewCell: UICollectionViewCell {

  @IBOutlet weak var imageView: UIImageView!
  var image: UIImage = UIImage() {
    didSet{
      self.imageView.image = image
    }
  }

  func offset(offset: CGPoint) {
    self.imageView.frame = self.imageView.bounds.offsetBy(dx: offset.x, dy: offset.y)
  }
}

I just can't see any offset when cells are displayed. What I do wrong, guys?

wm.p1us
  • 2,019
  • 2
  • 27
  • 38

1 Answers1

0

Make sure that you don't have any IB Constraints enabled on imageView, they will keep you from updating the frame.

Wes
  • 1,032
  • 7
  • 11