How can I set black color to my label background color when dark mode is off? - swift

I want the background color of the label to be black when dark mode is OFF and the background color of the label to be white when dark mode is ON (iOS 13).
Which UIColor value gives me black in light mode and white in dark mode?
When the user turns on dark mode, all blacks should change to white. UIColor.black doesn't work.

In iOS 13, UIColor.label is black in light mode and white in dark mode.
someLabel.backgroundColor = .label
Of course you now need an appropriate textColor for the label so you can read the text. Using UIColor.systemBackground will give you white in light mode and black in dark mode.
someLabel.textcolor = .systemBackground

um, for black, use UIColor.black and for white, UIColor.white?
It sounds like you're asking how to make your app respond to the user selecting/deselecting dark mode. I suggest reading the Apple document on the subject:
https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface/

Related

Text color based on background brightness in Flutter without opacity

In a freshly generated Flutter project, there is a counter with this style: Theme.of(context).textTheme.headline4. As you can see in the picture below, it has some minor opacity by default. In addition, if I modify the brightness to Brightness.dark in ThemeData, it adapts to the grey background by changing the font color to white automatically, but it still has some opacity. What I need is to have pure dark and pure light adaptively based on the background's brightness for Theme.of(context).textTheme.headline4.

Dark Mode - Button and font colors

Currently I have a button that changes the background color of my app (my users complained that it melted into other windows when grey, but others wanted that color scheme). I have 3 color options: grey with black text, light blue with blue text, and purple with white text.
Problem 1:
Dark mode is messing with my color scheme - can I set something up to adjust based on if they have dark mode on? Otherwise, I'm going to have to end up with grey text with a grey background in order for it to be ok when it switches back to grey.
Problem 2:
Button text - this wasn't so bad when using light mode because the buttons didn't change color, but on dark mode, this gets hard to read the button. White text on a light blue background hurts my eyes
I'm unable to attach images due to my level
I'm using Xcode 11.5, swift 5, and I'm coding for a Mac Application
Sounds like you are using the system color for the text / background color. And in dark mode, IOS will automatically change the system color for different mode. For reference:
https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/#dynamic-system-colors
Indeed for both problem 1&2, if you want to use custom color (not the system one) for each mode, you can put your color sets into an asset file (and I would suggest adding a new one, rather than adding all color together with your image). For each set of color, set them to the desired appearance (any, light, dark), then set the color by code.
Apple give a detail documentation about that:
https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface

How to change modal background in react-native-picker-select?

I want to try changing the background color of modal from white to black. that's because I'm implementing the dark mode and light mode features

Emacs, hl-line background. How set background color with transparent?

Windows 7, Emacs 25.1
If I want to change background color of hl-line I do:
(set-face-background 'hl-line "#333333")
OK. But how I can set transparent (e.g. 50%) for hl-line background color?
As far as I know, you cannot do what you ask. An Emacs frame can have an alpha parameter that specifies that the frame be transparent to a given degree. But the same is not true for an Emacs face.
However:
You can, for example, make the background of face hl-line be close to but slightly different from the frame background color.
If you want to make text shown in a given face "disappear" against the background, you can give the face used for that text a foreground color that is the same as the frame's (i.e. default face's) background color.

Figuring out the text color based on background view color iOS

I have these Views on which I add UILabels as text, The Views can have a background color that is dynamic and cannot be chosen,
Based on that I need to figure out the font color from only a set of three choices - two black or white or dark grey.
For example on a dark red background, a white font would be more suitable than black, while on a light yellow, perhaps a dark grey or black would be readable,
is there any index i could check from the background UIColor to see the illuminance?
Take a look at my UIColor category and the blackOrWhiteContrastingColor method. This will tell you what will look better out of black or white. You could extend that to support dark grey as well.
Basically the way it works is to look at the luminosity difference between the target colour and black, and then between the target colour and white. It then chooses the biggest luminosity difference.