Figuring out the text color based on background view color iOS - iphone

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.

Related

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 add a debossed effect to text in a highly textured image using CG-methods in Swift

I have to write some text on a custom CGRect with a highly textured in a CGContext.
This has work for dark and for light images. The texture has to be visible at the debossed letters.
Current approach
calculate avg. color of background image
darken (related to the luminance) the color
CGRect.drawText... with the ID with color of 2.
add a darker ouster shadow to text
add a light inner shadow to text
done.
Problem
My current approach works for dark, slightly textured backgrounds but it does not work for dark strong textured backgrounds.
Example usecase
Render license plates with an embossed ID for a car app.
or
Dog tags (see wikimedia)
It was a rough play with background color of the material, background color of the embossed thing and 4 different shadows.
All in all I have (sorry for that) no 'how to do it' solution. Thanks for your help.

How to create an art asset that can be dynamically colored in software?

I asked this question on the Graphic Design site, but it includes a programming component that might be better answered here.
Specifically, I have a bunch of photographic crayon images. I would like to remove the color from one to produce a neutral image that I can load into an iPhone app that I'm writing and dynamically color. The crayon images have dark regions (shadows) and light regions (shine) which I would like to preserve. I will be dynamically coloring it with many different colors, ranging from white to rainbow colors to black.
My first inclination is to turn the image into a grayscale image and then somehow turn the color channel into an alpha channel, and change the color of all pixels to black. Then I could use it as a mask. However, this would only preserve the shadows, and I would lose all the highlights.
Any ideas?
Two options come to mind:
Make a grayscale version that could be tinted as you said, with the shadows and highlights simply white and gray.
Make an outline, i.e. an image with alpha that had 0% opacity in the colored parts, say 10% white over the highlights, 10% black on the shadows, and 100% black/dark gray for the lines/edges. The idea being that you could put any color under the outline and it would look right.

What is background color of uipicker control?

I am using a uipicker as an input view for a text control. I also have a toolbar set up as an accessory input view. I would like the toolbar tint to match the picker. I have tried using the magnifier tool on the color chooser to get the RGB for the picker, but when I use these RGB values to set the tint on the toolbar I get get a close, but not exact match.
Is there anyway to figure out exactly the background color of the picker? None of the palettes in the color chooser seem to have this particular shade of gray with a slight hint of blue.
Thanks,
Jenny
The border consists of a gradient for the top half and a solid color for the bottom half:
As for the 'white' background, the brightest part is a #fafafa to #5f627c gradient.

Change background color of UIModalTransitionStyleFlipHorizontal

I would like to change the color behind the flip from white to a different color or picture. Is that possible?
Change the background colour of the UIWindow in MainWindow.nib. Either "black" or "clear" should both work (I think...)
It's one of the first things I do to any app, otherwise you get bits of white showing on a view rotation (in the very old days of 2.x there were huge patches of white; they've since masked off the screen edges during a rotation, but a few pixels still show through) and when you show/hide the status bar (e.g. for UIImagePicker) and stuff. Black looks a lot better than white for the window background.