Setting the image of a UIImageView in Interface Bu

2019-04-29 09:49发布

When ever I set an image for a UIImageView in IB and simulate the interface the buttons and stuff show up but the image view doesn't.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-04-29 10:15

That's because the simulator used by Interface Builder is independent of your project. It's just taking your xib files, building the interface, and displaying it. As such, any resources it finds references to but can't find will be skipped. So if your UIImageView uses an image named "myImage.png", then when the simulator runs, it's going to try to execute [UIImage imageNamed:@"myImage.png"];. Since "myImage.png" is not part of the Simulator bundle, it will fail to create the image, and your UIImageView will be blank.

It can create buttons because (obviously) buttons are standard, globally available code. Your project-specific resources are not.

查看更多
登录 后发表回答