我是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];
答案 0 :(得分:1)
尝试替换
UIImage *myImage = [UIImage imageWithContentsOfFile:@"banana.jpg"];
与
NSString path = [[NSBundle mainBundle] pathForResource:@"banana" ofType:@"jpg"];
UIImage *myImage = [UIImage imageWithContentsOfFile:path];