【问题标题】:IPhone Development - Setting Background Image For IPad From A Downloaded ImageiPhone 开发 - 从下载的图像中为 iPad 设置背景图像
【发布时间】:2023-03-19 02:20:01
【问题描述】:

我是新手,这周搜索了很多。我正在尝试从我从 url 下载的文件中设置背景图像。我需要保存图像以备后用。特别是如果我没有连接到互联网,我仍然可以显示此图像。

我已通过打印出该文件存在的目录内容进行了验证。这是我尝试让图像出现在背景中的众多代码之一。

nNSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *documentPath = [docDir stringByAppendingFormat:@"/mainback.png"];

// If you go to the folder below, you will find those pictures

NSLog(@"%@",documentPath);



if ([[NSFileManager defaultManager]fileExistsAtPath:documentPath]) {

    NSData *data = [NSData dataWithContentsOfFile:documentPath];

    UIImage *image = [[UIImage alloc] initWithData:data];

    NSLog(@"WHAT - %f,%f",image.size.width,image.size.height);

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:documentPath]];

    self.view.backgroundColor = background;

    [background release];

}

代码在目录中找到图像,但我无法将图像设置为背景。请帮忙。

谢谢

【问题讨论】:

    标签: iphone objective-c image ipad background


    【解决方案1】:

    使用UIImageView(Apple 文档链接)而不是使用 UIColor 执行您尝试执行的操作。

    这会更简单,问题更少。

    【讨论】:

    • 我需要它作为背景图像,因为我必须在它的前面显示一个表单。我可以使用 UIImageView 显示背景图像吗?没有在网上找到任何例子。感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多