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

后端 未结 15 695
孤街浪徒
孤街浪徒 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:12

    Note that the NIB file doesn't wire up all the IBOutlets until the view has been added to the scene. If you're wiring things up manually (which you might be doing if things are in separate NIBs) this is important to keep in mind.

    So if my test view controller has an "imageView" wired by a nib, this probably won't work:

      testCardViewController.imageView.image = [UIImage imageNamed:@"EmptyCard.png"];
      [self.view addSubview:testCardViewController.view];
    

    But this will:

      [self.view addSubview:testCardViewController.view];
      testCardViewController.imageView.image = [UIImage imageNamed:@"EmptyCard.png"];
    

提交回复
热议问题