【发布时间】:2017-04-05 14:29:32
【问题描述】:
我正在创建一个自定义框架。以前在框架中,我们会下载图像并使用它来显示在按钮中:
NSString *path = [NSString stringWithFormat: @"https://s3.amazonaws.com/assets/home.png"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *homeButton = [[UIImage alloc] initWithData:data];
self.rewardsCenterButton = [[UIBarButtonItem alloc] initWithImage:[homeButton imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
style:UIBarButtonItemStylePlain
target:self
action: @selector(backToRewardsCenter:)];
但是,在审查此内容时,我们确定这不适合作为同步调用,因此我想将此 PNG 添加到框架本身。
我已经能够通过添加图像并确保它包含在复制捆绑资源构建阶段中来做到这一点。使用此设置,图像将添加到通用框架输出中:
但是,当我尝试在代码中添加它时,它似乎没有出现。另外,当我在项目中添加框架时,我没有看到包含的图像,只有标题:
这是我迄今为止尝试过的:
NSString* path = [NSString stringWithFormat:@"%@/TheoremReachSDK.framework/home.png", [[NSBundle mainBundle] bundlePath]];
UIImage *homeButton = [[UIImage alloc] initWithContentsOfFile:path];
还有:
NSBundle *bundle = [NSBundle bundleForClass:[TheoremReach class]];
NSString *path = [bundle pathForResource:@"home" ofType:@"png"];
UIImage *homeButton = [[UIImage alloc] initWithContentsOfFile:path];
还有:
UIImage *homeButton = [UIImage imageNamed:@"home.png"];
但这些都没有显示任何内容。知道我需要做什么才能显示图像吗?
【问题讨论】:
-
你为你的框架提供了什么包 ID?
-
不确定 - 我怎么看?我不确定我是否设置了...
-
查看你的 bundle 的 Info.plist 文件
-
在框架中设置为
$(PRODUCT_BUNDLE_IDENTIFIER)。
标签: ios objective-c uiimage