有没有办法检查通过 nib 加载的视图以查找 imageView 中图像的资源名称?
寻找支持视网膜显示的简单方法。我突然想到,如果我可以查看笔尖加载的视图并获取那里使用的所有图像资源的名称,我可以检查它们是否有相应的视网膜图像并加载它(如果它是视网膜设备)。
我知道如何在加载后遍历子视图,但我不知道如何(或者是否可以)获取 Interface Builder 中设置的资源名称。我试图避免在代码中设置所有图像名称。
我想做的事情(用伪代码):
for subView in self.view.subviews:
if subView is UIImageView:
resourceName = (UIImageView *)subView.imageName
if retinaResourceFileExists(resourceName) and isRetinaDisplay:
(UIImageView *)subView.image = retinaImage(resourceName)
(奖励:也许有一种方法可以迭代 IBOutlet 变量,但我对此表示怀疑?)
Looking for easy way to support retina displays. It occurred to me that if I could look through a nib-loaded view and get the names of all the image resources used there, I could check if they have a corresponding retina image and load it (if it's a retina device.)
I know how to iterate through subviews after it's loaded, but I don't know how (or if you can) get the resource name set in Interface Builder. I'm trying to avoid having to set all the image names in code.
What I'd like to do (in pseudo code):
for subView in self.view.subviews:
if subView is UIImageView:
resourceName = (UIImageView *)subView.imageName
if retinaResourceFileExists(resourceName) and isRetinaDisplay:
(UIImageView *)subView.image = retinaImage(resourceName)
(Bonus: Maybe there is a way to iterate through IBOutlet variables, but I doubt it?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
[UIImage imageNamed:@"Foo"];
,设备将自动加载@2x图像。Interface Builder 也会自动加载视网膜图像。
use
[UIImage imageNamed:@"Foo"];
and the device will load the @2x image automatically.Interface Builder loads the retina image automatically, too.