Imageview changes location on runtime - Swift

173 Views Asked by At

Hello,

My imageView that I have set in my custom table view cell moves the set image to a different place on run time.

The thing that confuses me is that if I manually set the image in the attributes inspector the image is in the place it is supposed to be. Only when setting the image programatically does this problem arise.

Below is the code I am using my cell creation function to generate the tick or cross.

// Cell Information

    if answersBool[indexPath.row] == false {
        cell.imageView!.image = UIImage(named: "crossIcon.png")
    } else {
        cell.imageView!.image = UIImage(named: "tickIcon.png")
    }

This is what happens on run time.

This is what the cell looks like in my storyboard.

2

There are 2 best solutions below

2
On BEST ANSWER

First of all remove all constraint from your imageView after that select your imageView and click on pin menu then add this five constraint shown in below Image:

enter image description here

Hope it will help you.

1
On

You need to constraints for your imageView in storyboard.

Try sticking it to right.