1

I'm currently working with nibs need to change the images based on their tag programmatically based on country. I've tried:

vc.view.viewWithTag(8).image = UIImage(named:"image")

but it throws an error "Value of type UIView has no member image", any clue on how to do this?

SwiftyJD
  • 5,257
  • 7
  • 41
  • 92

2 Answers2

3

viewWithTag will give UIView in return. But you need ImageView type. So you need to explicitly cast it and assign the image.

if let imgView = vc.view.viewWithTag(8) as? UIImageView {
    imgView.image = UIImage(named: "image")
}
Sivajee Battina
  • 4,124
  • 2
  • 22
  • 45
0

You have to cast the view. I'm on mobile but it's something like this:

if let imageView = vc.view.viewWithTag(8) as? UIImageView {
 // Stuff here 
}
Salman Ghumsani
  • 3,647
  • 2
  • 21
  • 34
Cesare
  • 9,139
  • 16
  • 78
  • 130