当我的 iPhone 应用程序第一次运行时,它会要求您从 iPhone 库中选择一张图像作为整个应用程序的背景。以下是相关代码:
/*
* Responds when an image is selected (from browsing)
*/
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
//Not really sure what to do here
UIImage *image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation([info objectForKey:UIImagePickerController], .2)];
}
}
我现在要保存此图像(或对此图像的引用),以便我可以在整个应用程序中使用它作为我的某些(60%)的背景UIViewController
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
最好/最有效/最简单的方法是什么。我想过将图像保存到其中NSUserDefaults
,但这似乎不正确,因为NSUserDefaults
它只应该用于小物体。我应该将其保存到磁盘吗?但是,我的应用程序在每次 segue 时都必须从磁盘读取数据会不会很慢?(如果这是正确的方法,我该怎么做?)