Magic behind views automatically adapting to ios13 dark mode? - ios

I found it quite weird that for new projects created by xcode 11 beta, common views like UILabel, UIButton in a storyboard can automatically adapt themselves to system theme changes without any code. But for my old projects still using XIB, even though all colors are set to default, they dont change when system theme changed, i still have to manually override traitCollectionDidChange and assign them system default values in order to make them change! What am i doing wrong? thanks.

I figured out. The magic is the newly added system colors to UIColor on ios 13, for example, UIColor.systemBackgroundColor, it will be white in light mode and black in dark mode, once you assign a system color to a property, it always updates itself based on system theme. So i guess UIViews created in xcode 11 beta storyboards automatically have system colors on.

Related

iOS 11+ launch screen - custom named colors in dark mode

Is it possible to use user defined named colors in the launch screen storyboard?
I tried creating test color in xcassets, with appearances {dark, any} and setting it as Launch screen main view background.
I noticed significant differences:
- in RELEASE my custom colors never work
- in DEBUG some colors work, some are ignored, some are changing values (e.x. dark color is correct, but light is biased), and generally it is a mess
I know I need to delete app every time since launch screen is cached, are there any additional constraints? I fail to get any consistent results. Only thing that seems to work is "System background color".
Similar question goes for images.
OK, so short update. It is possible to use named colors and images with dark appearance on the launch screen after all.
It just works like nightmare. Which means that some parts are getting somehow cached (not sure what is happening underneath).
The final result is that to get consistent results, I had not only to delete app from the device, but also restart the phone.
I also noticed, that images with dark appearance are somehow broken - twice bigger or twice smaller, than their "any" appearance counterparts (even when I used exactly same files). That altogether creates unbelievable mess making it hard to test.
This is still a mess in iOS 13. I ended up using the build in dynamic system colours and tinting them with an overlay.

Dark mode don't update instantly

I have implemented dark mode in my iOS app, and while it works, the changes don't occur immediately. I think this has to do with the views not recreating themselves all the time like they do in android.
For instance, it doesn't work to go out from the app, then to settings and change theme, then back in the app again. The changes have only then occurred to Apple-related framework like alertControllers. To get dark mode to work I have to click around to a new view, then go back to the old view again.
I have tried adding dark mode code in the delegate, as I thought this would run every time you reenter your app, but it didn't.
So, any ideas on how to make this work? Is there for instance a delegate that is run every time I reenter the app, or can I have an observer to dark mode changes?
You could implement this method to "listen" to TraitCollection changes:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
// do whatever you want to do
}
Also, as Gergely mentioned, try to use xcassets for colors and images so they dynamically change depending on the current TraitCollection.
Alert view controllers update because they use responsive system colors for their text and background, which have versions for both light and dark mode by default and update automatically once the mode changes.
You can do the same with custom views if you use color and image assets. this is a nice overview of how to do things: Medium Article.
The official Apple documentation also has a nice overview of how to support dark mode: Supporting Dark Mode in Your Interface.

Set specific background color in iOS LaunchScreen.storyboard (Visual Studio for Mac)

Ok, I can't believe I'm asking this but... how do you set a specific color as the background of a UIView. I mean:
I select the UIView.
I set #2374A5 as the background color (using the color picker).
Visual Studio sets #1D5F93 as the background color (what??).
EDIT: Ok, just after I posted the question I remembered that I could actually edit the Storyboard in XCode Interface Builder and, there, it worked as expected. However, I'm still puzzled as to why VS changes the color I choose. Is it a bug, or is there any obtuse logic behind it that I'm not seeing?

Why does ios dismiss all my UITextView fonts

All my UITextViews are created through the storyboard. I used to have the fonts as body. But now I want to change them to System Fonts. So I go to storyboard and change them there. When I run the app, the new fonts are ignored completely. I even change the sizes to 22 just to see some effects but nothing happens. Any ideas what sort of global setting might be doing this?

Is this the right way to make an iPad app full screen?

I want to disable the status bar in iOS to make my app full-screen. I managed it but I'm not sure I did it correctly.
Here's what I did:
In IB, set the Simulated Metric for Status Bar to None
Added an entry in the Info.plist UIStatusBarHidden = YES
Moved my views around in IB so they fill the screen.
I'm not using OpenGL or anything like that, it's just a straightforward Cocoa Touch app which, like many others of a similar type, benefits from having access to every pixel on the screen.
To my shame I got the technique from one of those omnipresent 'tutorials' that litter the web like the dust bunnies under my bed. It was dated 2009. Is there a more modern, approved technique I should be using instead?
If it helps I'm targeting iOS 5 only.
The statusBarHidden property of the shared UIApplication object controls whether the status bar is visible. The UIStatusBarHidden entry in the app's Info.plist sets the value of that statusBarHidden property when the application is launched. You can change the property's value to hide or show the status bar while your app is running.
These are the current methods for controlling the status bar's visibility as of iOS 5.0.1.

Resources