UIImage不加载图像

时间:2013-02-23 07:26:12

标签: ios cocoa-touch uiimage

以下代码正常工作..

scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 1024, 200)];
scrollView1.contentSize = CGSizeMake(2048, 200);
scrollView1.showsHorizontalScrollIndicator = YES;
scrollView1.scrollEnabled = YES;
scrollView1.userInteractionEnabled = YES;
scrollView1.backgroundColor = [[UIColor alloc] initWithRed:0.5 green:0.8 blue:0.5 alpha:1];
[self.view addSubview:scrollView1];

但这个不是......

scrollView1 = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 200, 1024, 200)];
scrollView1.contentSize = CGSizeMake(2048, 200);
scrollView1.showsHorizontalScrollIndicator = YES;
scrollView1.scrollEnabled = YES;
scrollView1.userInteractionEnabled = YES;
scrollView1.backgroundColor = [[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:@"image.jpg"]];
[self.view addSubview:scrollView1];

UIImage有什么问题?在我的完整项目UIImage无法在任何地方工作....

在我的调试器中,即使在内存分配之后,所有uiimage变量都显示内存地址0 * 000000000

注意:: ScrollView1工作正常,“image.jpg”是正确的参数。

1 个答案:

答案 0 :(得分:1)

[UIImage imageNamed:@"image.jpg"];

试试这样。这会对你有所帮助。

<强>编辑:

NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
scrollView1.backgroundColor = [[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:path]];