IPhone: Show splash screen from Documents folder

In my application, I need to display a splash screen. I am collecting an image from a url and saving it as Default.png

in my documents folder.

I saved the image successfully and put the path together.

My problem is that it doesn't show up. I am not getting any errors and in the log I have the correct path too.

This is my code:

 NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"/Default.png"];
    imgView=[[UIImageView alloc] init];
    imgView.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];    

    [self.view addSubview:imgView];

      

I got the correct path in workSpacePath

.

+3


source to share


4 answers


Do not overwrite the image with the method [UIImage imageNamed:]

. This method only works for images that are part of your package. It will return null for a path in your document directory. And because of that, you set imgView.image

nil. This means delete the image.

this should work:



NSString *workSpacePath=[[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Default.png"];
imgView=[[UIImageView alloc] init];
imgView.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];    
//imgView.image=[UIImage imageNamed:workSpacePath];
[self.view addSubview:imgView];

      

But you cannot replace the "real" screensaver. However, you can display a different image after the original splash screen disappears.

+6


source


The "splashscreen" is in the image commonly called Default.png

and is included in the app bundle. Since you are not allowed to change the contents of an application package, you cannot change the splash screen for your application.



+3


source


Default.png must be linked in the app bundle. It cannot be loaded via an external path as you need, i.e. From the document directory path.

One specialized solution is that you have to create your view as the splash screen that will act as the splash screen and disappear after a certain amount of time.

+1


source


the way you are doing the thing looks like you are just trying to show the image in the image view - i am not interested in replacing the default splash image as you cannot do that, but for you you only have to do:

imgView.image=[UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]];
imageView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
[self.view addSubview:imgView];

      

0


source







All Articles