的UIImage不加载图像
问题描述:
下面的代码工作很好..的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的”是正确的论据。
答
[UIImage imageNamed:@"image.jpg"];
试试这个。这对你有帮助。
编辑:
NSString *path = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
scrollView1.backgroundColor = [[UIColor alloc] initWithPatternImage:[[UIImage alloc] initWithContentsOfFile:path]];
是一个已经工作...任何想法可能是错误的上面的代码。为什么变量内存一直显示为空。 – bhawesh 2013-02-23 07:37:52
initWithContentsOfFile方法将图像数据加载到内存中并将其标记为可清除。如果数据已清除并需要重新加载,则图像对象将从指定的路径再次加载该数据。这里image.jpg不是路径。它只是一个名字。 – 2013-02-23 07:42:20
然后根据你什么可能是问题的解决方案...完整的图像路径? – bhawesh 2013-02-23 07:45:43