I am attempting to add a dark mode to my app and I have it almost done but I am having trouble with this one piece. When I call
self.present(vc, animated: true, completion: nil)
my image below pops up in front of my previous view. However, the top coloring is white still instead of dark. I have tried numerous different background color changes but can't seem to find the correct layer to change the background on. Does anyone know what layer this is to so I can change it to black to complete my dark mode?
Although that should be black by default, it's window's background view. So you can change it to any color you want:
view.window?.backgroundColor = .yellow
Note that you can use .systemBackground as color. so it's automatically the correct color in either light or dark mode.
And also note that the window color only needs to be set once (per window). Set it in the App/Scene delegate and be done
All views have access to their window
Thanks to #rmaddy for the notes
Related
Say I want to mimic this "Shut Down" blue-tinted button in the iOS Settings app using the new (as of iOS 14) cell content configuration options:
How would I do this in a way that would also allow it to be properly dimmed if a user presented, say, an alert controller over top? For the unaware in this case it "dims" all the interactive/tinted views like this one to a grey color. Here's an example where an alert controller is shown over a grid of UIImageView buttons with a normally blue tint where you can see they're grey due to the action sheet:
But with cell content configurations, at least the default one, the only option I get for changing text color is via textProperties.color = ..., and since this isn't technically a "tint" (and there's no tint option I can see) it remains blue even when other views properly dim.
How do I fix this?
I tried reading the value of tintAdjustmentMode in the updateConfiguration method of the cell subclass, but it's not called for tintAdjustmentMode changes. I then tried calling setNeedsUpdateConfiguration() manually when tintColorDidChange() is called on the subclass, but that causes a brief delay in the color changing which looks bad/out of sync with other views.
Is there a way to do this that I'm missing?
I am running into a problem in xcode storyboard to setup the graphics of an app.
Nothing complicated, but I seriously don't understand the logic.
Import an image view that will be the background. It is set as opaque, alpha = 1, it uses an image found on internet and the background is "default". It covers the whole iphone surface
Import a text view. Now I am trying to have the background colour of the text view white.
To do that, on the "Text Field" section, I have tried to use an image of white, found on the internet, no success. I have also tried in the "View" section to set the "Background" to white colour with alpha=1 and opaque activated, no success, the text view background looks exactly like the background picture, it does not stand out.
Does anyone know how to do this ?
In case anyone wonders, I have been able to solve this programmatically using code lines like :
myTextField.backgroundColor = UIColor.white
Still not sure why it does not work on the interface builder though.
I am using a lot of different background images in my project and I wanted to know how can I adjust the UITextLabel colour according to the Background Image View on my View Controller? i.e. if the background is dark the text will become .white whereas if the background is light the text will become .black. Any help will be highly appreciated:)
If you are okay with using third-party libraries, what I would suggest is to use
https://cocoapods.org/pods/ChameleonFramework
to get access to its function
ContrastColorOf(backgroundColor: UIColor, returnFlat: Bool)
My tableViews are working fine with Background = Default, but the rest of my views always display as Dark. What am I doing wrong? I am new to this...
I think the default background color of a view transparent. Probably Xcode is just showing it as black when it's actually transparent.
If you want an actual, adaptive background color, use System Background Color instead (this will be white or black). If you need different shades, there are also the Secondary and Tertiary options.
I would try hardcoding it in, like background = #fff(for hex0 or background = rgb(255,255,255). Sorry if it doesnt work, Im usually a flutter dev, not swift.
I have a couple questions about the iOS tab bar.
My first question is, is the image always tinted automatically? Say for example, I used an image that was colored red, is there a way to get it to show the red without tinting it? I guess what I am saying is, can you show the natural color?
My second question is, assuming the tinting is mandatory, how would I go about tinting the images in the tab bar that are not the currently selected image? I have the selected image tint figured out.
I tried changing the tint under, UIView.appearance() I believe and that worked, but when I selected a different tab, and then navigated back the color went back to the former grayish color.
If I am not being clear enough, let me know and I will explain more. I am using swift, so any examples you give would be great in swift! Thanks!
Say for example, I used an image that was colored red, is there a way to get it to show the red without tinting it?
What you want to do is to specify an image with rendering mode .AlwaysOriginal.
To govern both images, create the item with initWithTitle:image:selectedImage: and make them both .AlwaysOriginal.
(As you discovered, if you use a transparency mask and rely on the tintColor, you lose control of the tint color when unselected.)