ios - 将图像添加到 Titanium iOS 模块

标签 ios titanium

官方文档似乎已经过时,并且其解决方案均不适用于在 Titanium iOS 模块中使用图像。

根据 http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project ,我应该将图像放在 Assets 目录中并使用相对路径在 Objective C 代码中获取它。我按照它说的做了,但图像是空的。

我找到了实际的应用程序包,发现图像在 modules/moduleid/xxx.png 中,但代码就是无法加载它。

最佳答案

而是遵循官方指南,例如(这显然不起作用):

NSString *path = [NSString stringWithFormat:@"modules/%@/foo.png",[self moduleId]];
NSURL *url = [TiUtils toURL:path proxy:self];
UIImage *image = [TiUtils image:url proxy:self];

这样做:

NSString *imageName = [NSString stringWithFormat:@"modules/%@/foo.png",[self moduleId]];    
UIImage *image = [UIImage imageNamed:imageName];

在大多数情况下,此代码将在自定义 View 中,这意味着 moduleId 将被硬编码。

关于ios - 将图像添加到 Titanium iOS 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31483725/

相关文章:

javascript - 未捕获的类型错误 : Cannot read property '1' of null

ios - 我如何通过 swift 3 的 snapkit 向任何 UI 添加动画?

iOS:iAd 单例混淆

ios - 2个 View Controller ,每个都有自己的xib,其中一个是另一个的子类?

iphone - 在 Grand Central Dispatch 中使用串行队列的 dispatch_async 与 dispatch_sync

ios - NSDateFormatter 在 Titanium 中等效/在 Titanium 中以指定格式转换日期

javascript - 使用 Titanium Mobile 编译应用程序后 JavaScript 代码会发生什么

ios - 如何将 JSON 对象数组从 Meteor Collection API 转换为 iOS 对象?

javascript - 在 Titanium 中分离平台特定代码的最佳方法

ios - 在 Appcelerator Titanium 应用程序中打开另一个窗口不起作用