How can I change the image displayed in a UIImageView programmatically?

后端 未结 15 683
孤街浪徒
孤街浪徒 2020-12-07 08:42

I have an IBOutlet to a UIImageView, but when I look at the UIImageView doc, I can\'t see any hints about programmatically changing it

15条回答
  •  执笔经年
    2020-12-07 09:08

    This question already had a lot of answers. Unfortunately none worked for me. So for the sake of completenes I add what helped me:

    I had multiple images with the same name - so I ordered them in sub folders. And I had the full path to the image file I wanted to show. With a full path imageNamed: (as used in all solutions above) did not work and was the wrong method.

    Instead I now use imageWithContentsOfFile: like so:

    self.myUIImage.image = [UIImage imageWithContentsOfFile:_currentWord.imageFileName];
    

    Don't know, if anyone reads that far?

    If so and this one helped you: please vote up. ;-)

提交回复
热议问题