I have a UIImageView and four buttons below it. Once the user taps one of the buttons it sets the image in the image view. The problem is I want to add constraints to the images in the image view. I added the images programmatically the code for one of the buttons looks like this:
overridefunc viewDidLoad() {
super.viewDidLoad()
let defaults = UserDefaults.standard
goldImageView.image = UIImage(named: "gold with Text"
}
@IBAction func gold(_ sender: Any) {
goldImageView.image = UIImage(named: "gold with Text")
}
To make OOPer's description even more clear --- you will be setting constraints on the UIImageView not the UIImage. You can do that in the XIB or Storyboard. Then you will be adding a UIImage to that UIImageView. You can add that UIImage programatically. When you switch the UIImage in the UIImageView it will not affect the constraints. If you want different constraints on the different UIImages then you can create multiple UIImageViews each with its own constarints. Then when you tap those buttons you will need to set the "hidden" value for those different UIImageViews.