在app和today widget之间共享图像资源 [英] Share image resources between app and today widget

查看:287
本文介绍了在app和today widget之间共享图像资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在主iOS应用和今天的扩展小部件之间共享资源(编译到应用程序中的图像)吗?假设我创建了一个新应用程序。然后将今天的扩展项目添加到解决方案中。然后我创建了一个UIImageView。我想从共享的图像池中引用一个图像,而不是每个图像中有两个,一个添加到主应用程序,另一个添加到小部件应用程序。

Can I share resources (images that are compiled into the application) between my main iOS app and my today extension widget? Say I create a new application. Then add a today extension project to the solution. And then I create a UIImageView. I want to reference an image from a shared pool of images rather than having 2 of every image, one added to main app and another added to widget app.

imageView.Image = UIImage.FromBundle("IMG_3799.JPG");

IMG_3799.JPG位于该项目的References文件夹中的主应用程序内。我更喜欢小部件引用相同的图像资源。那可能吗?目前,我正在制作IMG_3799.JPG的第二份副本并将其放入小部件中。

The IMG_3799.JPG is inside the main application in the References folder of that project. I'd prefer the same image asset to be referenced by the widget. Is that possible? Currently, i'm making a 2nd copy of IMG_3799.JPG and putting it into the widget.

推荐答案

开箱即用,你不能。

最接近的是创建一个包含主应用和扩展的应用组,并且可以访问公共文件夹。但是,在部署期间,只能在运行时期间放置任何文件,因此它可能是也可能不是您需要的解决方法,但这是唯一的方法。

The closest thing to that would be to create an app group that contains the main app and the extension and that has access to the common folder. However you can't place any file there during deployment, just during runtime, so it may or may not be a workaround for what you require, but that is the only way.

这篇关于在app和today widget之间共享图像资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆