Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView is black on launch screen

I sometimes face a very strange issue on launch screen. I'm using a xib file with just a UIImageView on it, however sometimes the image is just a black rectangle.

I've tried to switch between .jpg and .png files but this didn't help, I've also assigned a different image property profile to it.

This happens on devices running iOS 9.

enter image description here

These are the constraints for the UIImageView. I've removed the image, as it's a logo of a client.

enter image description here

enter image description here

like image 482
gpichler Avatar asked Dec 02 '15 12:12

gpichler


People also ask

What is the difference between UIImage and UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.

What is use of UIImageView?

Whenever you want an image in a view controller, you use a UIImageView. A UIImageView contains a UIImage, which is the raw bitmap, and allows you to configure how you want to scale or crop the image.

What is launch image in xCode?

A launch screen is the very first screen presented to users when your app starts up. When you create a new project with UIKit, Xcode automatically generates a storyboard file named LaunchScreen. storyboard for developers to design the launch screen of the app.


2 Answers

I have the same problem. I've tried:

  • move the .png file to Images.xcassets. fail.
  • create a new LaunchFile.storyboard. fail.
  • rename the .png file. work for a while, but after you perform the Build&Run action(same with Run without building action) a few times, the issues occur again. very weird.(sometime you need to reopen the Xcode to reproduce the issue)
  • test the same LaunchFile.storyboard in a new project. the LaunchFile is correctly displayed in the new project, very confused me.

Finally, i found a way which works not only for temporary(I've tested for one hour, just repeat build and run for like 100 times, watch TV meanwhile).

This issue is somehow related to the .png image. I dragged my .png file to photoshop, then go File > Save for web (Command + Option + Shift + S), make sure the transparency is unchecked, export a new .png file. replace the old file with then new one you'll find the issue is fixed.

But I'm still confused why a issued .png file can work for a while.

like image 63
vcrim wu Avatar answered Sep 28 '22 23:09

vcrim wu


I have the same problem that appears from time to time on some devices. Last thing that helped was a full restart of a device.

like image 28
Vlad Avatar answered Sep 28 '22 21:09

Vlad