ios - UIImage 不加载图像

标签 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”是正确的参数。

最佳答案

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

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

已编辑:

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

关于ios - UIImage 不加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15038225/

相关文章:

objective-c - 提取字母的结构

iphone - 使用 Alpha 设置为 subview 添加背景色

ios - 无法访问自定义 UIView 属性

ios - 放养 UIImages 然后转换为电影

ios - 可点击的 UITableView 部分

ios - 按钮动画无法在 swift 中正常工作

ios - 如何在设备屏幕因不活动而关闭时/之前立即执行方法?

objective-c - 将 UIButton 放入 UITableView 中

swift - 从cloud firestore下载图像并添加到用户对象

swift - 如何使用此代码向图像添加水印?