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?

4

2 回答 2

3

viewWithTag将给UIView作为回报。但是你需要ImageView类型。所以你需要明确地转换它并分配图像。

if let imgView = vc.view.viewWithTag(8) as? UIImageView {
    imgView.image = UIImage(named: "image")
}
于 2017-09-19T15:04:07.287 回答
0

你必须投射观点。我在手机上,但它是这样的:

if let imageView = vc.view.viewWithTag(8) as? UIImageView {
 // Stuff here 
}
于 2017-09-19T14:57:23.443 回答