Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone:Show splash screen from Documents folder

In my app, I need to display a splash screen.I collect the image from URL and saved it as Default.png in documents folder.

I successfully saved the image and collected the path.

My problem is that it is not displayed. I don't get any errors and in the log I got 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 correct path in workSpacePath.

like image 429
nithin Avatar asked Feb 16 '26 16:02

nithin


1 Answers

Don't overwrite your image with the [UIImage imageNamed:] method. This method only works for images that are part of your bundle. It will return nil for the path in your documents directory. And because of that you set imgView.image nil. Which means, remove 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 can't replace the "real" splash screen. You can however show a different image after the original splash screen disappeared.

like image 144
Matthias Bauch Avatar answered Feb 18 '26 05:02

Matthias Bauch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!