In a view displayed as a Popover, I implement a help subview (a NSView with a NSScrollView as a subview) that appears when user click on a button. With Sierra & High Sierra, everything was all right, but since I upgraded the dev MacPro to Mojave, the help bubble became slightly transparent. Elements (NSTextField or NSButton) being the help view are still visible as a white strip in Dark Mode (or as a gray strip in Light Mode)
I have defined the help view and its scroll view to have their own layer and these two layers are set as opaque
[help setWantsLayer:YES];
help.layer.opaque = TRUE;
help.backgroundColor = [NSColor colorWithRed:1. green:1. blue:140./255. alpha:1.];
[help.scrollView setWantsLayer:YES];
help.scrollView.layer.opaque = TRUE;
[help.scrollView setBackgroundColor:[NSColor colorWithRed:1. green:1. blue:140./255. alpha:1.]];
All background colours are set to this yellow tone.
This problem occurs only if the view that display the help view was presented as a NSPopover, not as a NSView from an ordinary window. Any idea?
add NSRequiresAquaSystemAppearance = YES in your info.plist
To run any app in Dark Mode, you must to be running macOS Mojave 10.14 or greater. By default, all existing apps will run in Light Mode even if the system is configured to run in Dark Mode. An app that is launched on macOS Mojave will run in Dark Mode when two criteria are met:
The system considers the app to be compatible with Dark Mode
The running application’s appearance is set to Dark Aqua
An app’s compatibility with Dark Mode is determined by a combination of the SDK it was built against, and the value of the “NSRequiresAquaSystemAppearance” Info.plist key. If your app is built against the 10.14 SDK or later, it will be considered compatible unless the key is set to YES. If your app is built against the 10.13 SDK or earlier, it is considered incompatible unless the Info.plist key is set to NO.
Related
In my iOS/macOS app the user can choose between a light and a dark appearance.
This is done by setting the overrideUserInterfaceStyle of the app window, for example
window.overrideUserInterfaceStyle = .dark
It works fine on iOS/iPadOS.
On macOS (Catalyst) the app uses an NSToolbar, which always appears in the mode chosen in the system settings, regardless what ist set for the overrideUserInterfaceStyle of the window (see screenshot).
Since this is not a good visual impression, I would like to know how I can set light/dark mode for the NSToolbar too.
Add UIUserInterfaceStyle with a value Dark to your app’s Info.plist. That will force the whole app to dark mode on iOS 13+ and Mac Catalyst (you won’t need to set overrideUserInterfaceStyle).
Docs: https://developer.apple.com/documentation/bundleresources/information_property_list/uiuserinterfacestyle
This can be done by adding an macOS plugin which has access to the whole AppKit API. Instructions can be found here:
How to Access the AppKit API from Mac Catalyst Apps
Then you can set the desired appearance there at runtime, for example:
NSApplication.shared.appearance = NSAppearance(named: .darkAqua)
I have an app which is currently published, this one person reported a problem with an iPhone 7 iOS 13.5.1 where he could not use it, basically the background of a table view cell is completely black where on all other devices is white, because of that and since the text is black, this person can't read anything. Also in the search field he can't see what is being typed, there, the background is white and the text which is supposed to be black is white. We actually got a screenshot which is by the way not very clear but you can see a faded version of the text in both the search field and the table view.
We also have the same model and with the same OS version installed but are not seeing the issue, for now we have only gotten report from this one person.
Has anyone experienced a similar issue that can point me to what the problem maybe?
You need to set your background color to white instead default.
"default" will set your background color in black if the device is in dark mode.
This looks to be an issue where your user has dark mode enabled, but your app appears to use a mixture of hardcoded and semantic colors.
As a quick workaround your can force your app to always use light mode by adding
<key>UIUserInterfaceStyle</key>
<string>Light</string>
to your Info.plist
I was using Xcode 10. Did not have enough space to update to latest Xcode. So downloaded it from Apple's website and removed the old Xcode. To make more space I deleted all the cache, unavailable simulators, derived data and unwanted stuffs following this. After that installed the new Xcode 11.3.
My app is build successfully. But the emulator is showing only black screen.
I tried
"Erase All Content and Settings"
and also
defaults write com.apple.CoreSimulator.IndigoFramebufferServices
FramebufferRendererHint 3
But still emulator is the same.
Switching from Xcode 10 to Xcode 11 enables the dark mode/Dynamic Colors on your project.
There are two possible scenarios for your problem,
The Simulator may be on the dark mode and your first view controller background automatically changes to dark mode.
The Simulator may be on Light mode, but you have set your first view controller to be in a dark colour
For the first scenario,
Go to Settings in Emulator -> scroll all the way down to Developer -> Switch off the dark appearance.
If you want to avoid using the interface Styles/ Light mode or dark modes, add the following in your info.plist file if you're opening as XML,
<key>UIUserInterfaceStyle</key>
<string>Light</string>
if you're using the plist file,
use the key,
UIUserInterfaceStyle
and set the String value as Light.
If you think you're facing the second scenario,
Change the dynamic system background colour of your view to a hardcoded UIColor in Interface builder or your ViewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
yourView.backgroundColor = UIColor.white
}
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.
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