iOS 13 DarkMode and LaunchScreen - Fallback for iOS 10 - ios

I have a blue logo on the launchscreen.storyboard on white background.
For the new DarkMode introduced with iOS 13 I like to invert the colors, i.e. blue background and white logo.
As we know this can be done using named colors from the asset catalogues, which change depending on the traits of the device.
This is working totally fine in iOS 11 and up but shows this error when trying to support iOS 10:
Named colors do not work prior to iOS 11.0.
I tried making a view controller for the launchscreen scene in code and set the colors there using the #ifavailable clause, but the compiler says a launchscreen may not have a custom class associated with it.
I also thought of using different launchscreen storyboards depending on the iOS version but I couldn't find anything about how to.
Anything I can do about it?
How to solve this problem?
Thanks,
Felix

As suggested here, the solution is to use a dynamic image for the background instead:
Create 2 images with the flat colors for light and dark mode.
Import them in your Asset Catalog and define the “Any”/“Dark” appearances.
Add a UIImageView in the background of your Launch Screen with this image (“Scale to Fill”, constrained to container).
This will compile even if your deployment target is lower than iOS 11.0, and will display the appropriate color at launch.

Related

UISegmentedControl images always black on iOS 13

I'm using a UISegmentedControl with images. I'm trying to use template images and tintColor, selectedSegmentTintColor and backgroundColor all have different colors so all should be visible but images are always black. Sample of this is here: http://github.com/tomspee/SegmentedControl13.
Is there any way to fix black images on UISegmentedControl?
This is what I now get on iOS 13:
This is what I had in iOS 12 and would like to get on iOS 13 as well:
To add: I've already implemented the next code to opt-out of dark mode:
<key>UIUserInterfaceStyle</key>
<string>Light</string>
go to Image Set in the assets folder and setting the images to “Original Image” under the Render As option.
See there are two reasons to show always black in iOS 13. With iOS 13 we have a black theme also. if you want to restrict the black theme. You can use the below code.
<key>UIUserInterfaceStyle</key>
<string>Light</string>

Issues with named colors on iOS 11 with Xcode 11 beta

I am trying to implement dark mode in my iOS app. I need to use named colors in order to do this, but I've run into a bit of a snag. Everything works fine on the iOS 13 simulator when switching between light and dark mode, and the colors are also correct in the iOS 12 simulator. The problem occurs when I try to run my app on an iOS 11 simulator. Any named colors that I've used in the storyboard default to the dark version of the color, and when I try to access a named color in code I get nil. Just wondering if anyone else has run into this
It's bug in Xcode 11 with IOS 11. Two issues with named colors in IOS 11
UIColor init method init?(named name: String) returns nil in IOS 11
Named color assets used in storyboard or xib files defaults to dark version some times.
Here are workaround for time being until it's fixed in upcoming Xcode release.
If UIColor init method init?(named name: String) returns nil you need to provide fallback color for light mode.
let color = UIColor(named: "myColor") ?? UIColor.black // default color for IOS 11
Named color issue for Story board and xib files, if you observe the changes in your xib file or storyboard after setting any name color you will notice there is a namedColor xml tag under resources tab. And for each namedColor there is fallback color there, that fallback color is being in IOS 11 case because named color isn't working. You can even see the warings in your console.
<resources>
<namedColor name="NavigationBar">
<color red="0.2669999897480011" green="0.70999997854232788" blue="0.046999998390674591" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
</resources>
Bug in Xcode 11 is that default value is set to dark mode version if your MacOS appearance is set to Dark and it picks light color version for default values if your MacOS appearance is set to Light. Workarounds to fix this for IOS 11.
You can set your MacOS appearance to Light. After that you need to open each and every storyboards or xib files in yours project once. Once you open it, editor will automatically pick the Light version of your colors and you can see in your source control that file is modified and default value will be Light version of your color asset. Note that every time your change any value in your color assets, you have to do this again for all the xib files using that named color.
Second is a bit complicated that your write a script that parse all the xib and storyboard files for your project and update the default RGBA values.
It seems that Apple know of it.
Quote from https://developer.apple.com/ios/submit/
Please note that apps built with Xcode 11 using named colors may
experience lookup failures (with no value returned) when the app runs
on iOS 11 or earlier. This will be fixed in a future Xcode update. To
avoid this issue, raise the minimum deployment target to iOS 12 or
later to submit to the App Store now, or rebuild with the next Xcode
GM candidate seed when it’s available.
Update 20190917
Build your apps using Xcode 11 GM seed 2, which includes SDKs for iOS
13, iPadOS, watchOS 6, tvOS 12, and macOS Catalina. Starting April,
2020, all iOS apps submitted to the App Store will need to be built
with the iOS 13 SDK or later. They must also support the all-screen
design of iPhone XS Max or the 12.9-inch iPad Pro (3rd generation), or
later.
Seems like problem is on Apple side. Even Xcode 11 GM seed also having this issue. People are discussing this issue on apple developer forums.
https://forums.developer.apple.com/thread/122053
Update Xcode for Version 11.0 (11A420a)
For the ones with this problem and on Storyboards, I recommend on your color-scheme to use the "Any Appearance" default to Light mode.
For example, for dark I have gray background and light its white, the fonts are the opposite, white and darkGray. Default everything to light mode, the IOS will interpret it as light and you won't have issues.
As you can see on my screenshots, my app is working properly on IOS 11.
If I don't do that, probably all my fonts will be white and user won't see anything at all.
I highly recommend adding all your colors in separate assets and any added color can be mapped to the new system colors so it will handle light mode and dark mode colors automatically for iOS 13 and it will take the default color for iOS 12,11,...
also, you can call it in your code using
UIColor(named: "systemBlue") ?? UIColor.blue

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

How to tell Xcode to automatically set image asset render mode in iOS 7

In Xcode 6 you can tell any image in an assets catalog to always Render As Default, Original Image or Template Image through the Attributes inspector. Like this
But this only works for iOS 8, not for iOS 7.
Is there a way to do the same but working on iOS 7 as well?
Note: I'm not looking for programmatic solutions (like those using things like image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];), but for a declarative one, either in images.xcassets panels or in storyboards and nibs.
It looks like if you set the button type to "System" (vs "Custom"), "templating" behaves as expected under iOS 7 for button images. Unfortunately, it still does not work for button background images and it does not allow using custom images for any other state than "Default".

Xamarin.Forms ContentPage.BackgroundImage

Xamarin.Forms
VS2013 IDE
I know there are other topics on this, but they don't answer my problem.
For Android, the background image works fine.
BackgroundImage = Device.OnPlatform("Resources/HTbg#2x.png",
"Drawable/HTMobile.png",
"Images/HTMobile.png");
For iOS, I can't get it to work.
I've tried the normal and retina versions of the image, which are of
the correct dimensions for those screens.
I've tried placing them in the root folder of the project
I've tried images with transparent or solid colored image backgrounds
In iOS, the background image, in any of the scenarios above, just shows a white screen ontop of all the CustomContentPage controls. I comment out the background line of code, and my page shows normally, with all controls and navigations links...
With the following code (no 'Resouces' folder), the page shows normally, but no image...
BackgroundImage = Device.OnPlatform("HTbg#2x.png",
"Drawable/HTMobile.png",
"Images/HTMobile.png");
How do you set the background image in iOS?
For this answer, I need to know the following:
Where do you put the image in the project so it's picked up properly?
What type of image do you use? Size? Resolution? Color depth? Transparency?
How do you let iOS 'know' what image to use if it's a 4s, 5s or 6/6+ iPhone?
EDIT
ContentPage.BackgroundImage is of type FileImageSource - meaning the correct resolution is loaded automatically; therefore the call should be...
BackgroundImage = Device.OnPlatform("HTbg.png",
"Drawable/HTMobile.png",
"Images/HTMobile.png");
But this still doesn't work. I'll add in the 4-inch image version and see if that helps...
This problem on IOS is solved by adding the required image to an IOS asset catalog. Xamarin.Forms WILL NOT load an image into the BackgroundImage property when it is located in the Resources folder as for versions of IOS pre 7. This might save someone some time.

Resources