mythicalcoder
mythicalcoder

Reputation: 3291

iOS Constraints of image view inside table view cell gets misplaced on scroll

The constraints for the image view inside Table view cell gets distorted on scroll.

The constraints are fine on initial load and view. Once the table view cell goes out of the view and we scroll back to get it, the image view gets displaced.

This is the screenshot of single TableViewCell. The globe icon is misplaced from its original spot (left of name and designation) and overlaps on the text below. Screenshot showing the misplaced image view

Screenshot of prototype cell from storyboard Screenshot of cell from Storyboard

The black lines show the constraints added on the storyboard. Using XCode 8.0 with Swift 3. I am doing something wrong with the constraints ?

Upvotes: 0

Views: 1203

Answers (1)

Yuchen
Yuchen

Reputation: 33036

It seems that you are missing a height constraint on the image view. Should be able to fix problem if you add that.

Also, maybe related as well, can you set your image view's content mode to aspect fit? Sometime like this:

ObjC

[self.imageView setContentMode:UIViewContentModeScaleAspectFit];

Swift

self.imageView.contentMode = .scaleAspectFit

Upvotes: 1

Related Questions