Launch Images for Dark or Light Mode - ios

How can I choose a different set of Launch images for Dark mode and for Light mode?
I have a LaunchImages set. When the application starts, an image is shown. For Light mode it seems good, however if I try to open my application on a device set to Dark mode (iOS 13), this image seems bad.
During the start application I can not use any code for dynamic changes and I have no options in XCode interface for managing it.

As the Launch Screen loads before the app starts executing, it would not be possible to change the launch images set programmatically.
However, in the Image Set tab, you can change the Appearance option to enable a different set of images for Light and Dark modes:
So, if you set this image in the Launch Screen Storyboard, the result would be as below:
On a side note, if the need is just to change the background color, not the images, you may set the Launch Screen Storyboard view background color to System Background Color and just use transparent PNG images.

Xcode 11 supports only storyboard Launch screen files. It means I
should use storyboards.
In storyboards we can use UIImageViews + images from .xcassets.
Assets support images with different variants: Light, Dark modes. You can apply constraints for positioning them on screen.
If you support iOS before 11.0 you can not use system dynamic colors for backgrounds of the screen view. In this case you put additional dynamic image to screen as background and apply leading, trailing, top and bottom constraints with negative values. Negative values are needed for covering Top and Bottom Bars. (I used -64px)

You need to add dark appearance for your asset, or for the asset color you are using, like in the image below:

You should do something like this to use light and dark mode images
Step 1 - Create image set in assets.xassets like this
Step 2 - Select Image select like this
Steps 3 - Change appearance to Any, Light , Dark like this
Add your images for any light and dark mode like this and use this image wherever you need it

Just for my experience, sometimes Launch image is changed when you erase your app, turn off your device and turn on again.

Related

iOS launch screen for light and dark modes

I follow the instruction in RSP-12931: Native resolution not supported on iPAD Pro to create an iOS LaunchScreen for my Delphi app. Now, with iOS 13, the problem is that I need 2 variants of this launch screen, one for dark mode and another for light mode. How do I create a basic launch screen in XCode that shows a customized background color w/ logo image in dark/light modes?
This is all done inside an Asset Catalog.
For the logo, open your asset catalog and select the image. Now, select the Appearances drop down on the right, and select Any, Light, Dark.
The Asset Catalog will now let you add different images for Any (pre-iOS 13), Light and Dark for that particular image:
For the background color, you'll need to define a custom Color set inside your asset catalog.
Press the + button at the bottom of your list of assets, and select New Color set.
Select the Color set that appears in your assets and, again, adjust the Appearances dropdown to read Any, Light, Dark.
You can now provide different colors for each mode using the RGB sliders underneath the Appearances dropdown:
Now, inside your storyboard you'll be able to select your custom color, and it will adapt depending on the mode running on the device:
You can test this by flipping the Interface Style widget at the bottom of the Interface Builder window between light and dark mode:
After adding images in assets catalog with respect to appearance. If the changes are not reflected, uninstall the application and restart the device.

Any, Dark for colors and Any, Light, Dark for images, why?

I am adapting an existing app to dark mode.
A certain view uses an image to represent the state of a feature. I have selected the image inside the assets catalog and modified its Appearances field from none to Any, Dark. Then I added images for the Dark mode and nope. When I run the app, the image does not appear when the device is on Light mode. That forced me to change that image from Any, Dark to Any, Light, Dark and then define images for the light mode.
I had a label on the same view and I changed that view to Any, Dark just to check and it worked properly.
Why one view works and the other doesn't?
Bug?
Should I change that label to Any, Light, Dark?
You need to put the light image into Any if you only have light and dark.
Any is used in iOS 12 and below where dark mode is not yet available. If you, for instance, had a dark theme before iOS 13, then you would put all your dark assets in Any and Dark and the (new) light assets in Light. This way the app remains dark in iOS <= 12.

How to support Dark mode launch screen in iOS 13 with custom color?

I am working on adapting my existing iOS 11+ app to the new Dark Mode in iOS 13. Using dynamic / named colors works without any problem to switch between been normal and dark appearance, except on the apps launch screen.
A simple XIB file is selected as launch image in the target settings
The launch screen works without any problem, except that the background color is not adapted to normal / dark mode.
The launch screen uses a dynamic / named color as background color. Lets say green is selected for Any appearance and red for "Dark appearance". No matter if the devices is setup to use normal or dark mode the launch screen always shows Any appearance color (green).
If the Any appearance color is set to some other value, e.g. yellow, the launch screen will appear in this color ==> The background color is setup correctly
Toggeling the interface style in Interface Builder shows the correct result ==> The background color is setup correctly
Using the same dynamic color in other places within the app (e.g. on the first view controller) works without any problem ==> The color is setup properly
Using a build in dynamic color like System Background Color works without any problem (white background in normal mode and black background in Dark Mode)
Using dynamic background image instead (as proposed in some other threads) has exactly the same problem (only shows normal appearance color).
So, how to get the launch screen to properly work with Dark mode?

Dark mode launch screen in iOS 13

I've updated my iOS app to work in dark mode on iOS 13 but I am having trouble trying to get the launch screen to look good.
Currently it is a bright white screen with the app logo which looks awful in dark mode. I have tried setting the background colour of the launch screen to be a colour asset that I made with "Any Appearance" being white and "Dark Appearance" being black - but the launch screen still always shows as white.
Is there any way to get my launch screen to work properly in dark mode?
When setting up the Launch Screen storyboard, set the view "Background" color to "System Background Color". This will be white in light mode and black in dark mode. No need to use your own color asset.
I found a solution that supports earlier iOS versions as well as custom colors for each mode, dark and light, in iOS 13.
Create an image asset, set Appearances to Any, Light, Dark, and load small solid pngs with your desired colors. In this case I am using orange for light, and black for dark.
Go to your LanuchScreen.storyboard and add an image view with that image asset. Place the image behind your image logo, set Content Mode as Aspect Fill, and constrain the view to the Superview in all sides. (Make sure that your logo looks good with the two backgrounds, or set its Appearance too)
This is where I had to do a trick. For some reason, I couldn't make the back image to show up. After checking some of the comments in Launch Screen storyboard not displaying image, I added the first image in the image asset to the target bundle
The color is static in older versions of iOS, and it works well with dark and light modes in iOS 13.
I was updating my app to support new Dark Mode for iOS 13, I put "System Background Color" for the View's background in my LanuchScreen.storyboard, but surprisingly it didn't work!
The Logo image on the page was changing correctly based on Light/Dark Mode, but not the background!
I was about to apply Jose's solution, but before that, I decided to completely remove the app from my device and try again. And it worked!!
I was missing colors from my color palette in Xcode defaulty offered colors so I created my own using Color.xcassets where I created custom color set with appearences Any, Dark and set my colors.
Then I can use them in autolayout same like System Colors even in LaunchScreen
Yes Launch Screen work in dark mode, First check the background colour of your "xyz" image. if it is ok. just delete you app from device or simulator, because some time Launch Screen cached by device or simulator and you will not get the update UI on it. if you will face same problem just follow my demo app github.com/Indolia/darkmode.git

Template Image doesn't get tinted on Launch Screen Storyboard

I am setting up my launch screen with storyboard, and I'm using an image that is set to be a PDF template image. My goal is to put this image in a UIImageView and set tint color to it via Interface Builder.
This approach works fine if I have such image view in my Main.storyboard, but somehow, on LaunchScreen.storyboard, the image doesn't get tinted and takes on the actual color rendered on the PDF.
I looked around for information online but haven't found much info on proper use of template image on Launch Screen.
Is using tint color supported on Launch Screens? If it is, what's the appropriate way to set it up?
Launch screen storyboards work differently than a general storyboard. They are basically substitutes for launch screen images.
There are some restrictions for them: they cannot run code, nor they can use custom fonts etc. These restrictions include not being able to use tint colors.
Tamás Sengel's answer is partially correct. But for now, you can use tintColor in LaunchStoroboard.
Follow these steps:
Go to Assets.xcassets and set Render parameter of your image to Template Image.
Then add your image and set it tintColor.
Notice that, if it doesn't work, this is not a reason to be upset. Try to reset your emulator by the following way: run Simulator and click Device -> Erase all Content and Settings. Аnd it should work.
In my case, my image wasn't showing at all. So I read about the following trouble shooting hints somewhere:
uncheck Clears Graphics Context in the attributes inspector of the UIImageView in your LaunchScreen.storyboard
delete app
restarting the iPhone/iPad
reinstall the app
try if it worked and repeat all the steps a couple of times until it works :D
After that I had no issues tinting a PDF image asset marked as Render as Template Image in the asset catalog. Tested on iOS 11 and 12.
Unfortunately those caching issues and all the Launchscreen caveats are poorly documented by Apple.

Resources