图片没有加载?

时间:2014-03-21 02:49:49

标签: ios uiimage

我是iOS编程的新手,对于我的生活,我无法弄清楚为什么我的图片没有加载。

UIImage *myImage = [UIImage imageWithContentsOfFile:@"banana.jpg"];
CGImageRef myBlock = [myImage CGImage];
CALayer *myLayer = [CALayer layer];
myLayer.contents = (__bridge id) myBlock;
myLayer.bounds = CGRectMake(0, 0, 417, 119);
myLayer.position = CGPointMake(0, 0);
[self.view.layer addSublayer:myLayer];

1 个答案:

答案 0 :(得分:1)

尝试替换

UIImage *myImage = [UIImage imageWithContentsOfFile:@"banana.jpg"];

NSString path =  [[NSBundle mainBundle] pathForResource:@"banana" ofType:@"jpg"];
UIImage *myImage = [UIImage imageWithContentsOfFile:path];