how to create day/night mode for my app - ios

I am looking to create a toggle in my application
Day | Night
Day is considered the default setting. When the user selects the Night mode i want all the color of all the UI elements to be inverted.
Here are the kind of elements i mean:
UILabels
Buttons
Tabs
Pickers
Window Backgrounds
Everything else that is a UI object
I have tried using the following:
[[UIApplication sharedApplication] keyWindow].tintColor = [UIColor redColor];
This has the following issues:
This does change the color of many elements of the app but not
all. Like for instance it does not change the color of the UILabels
It does not invert the color. It simply changes the color for all
the object to a particular value.
Does not change the background color of the window.
Is this even possible with a quick bit of code?

You need use the UIAppearance for customize your labels, buttons, etc.
You can see this tutorial. I think this can help you.

Related

How do you properly dim tint colors when tintAdjustmentMode is active and using the new contentConfigurations?

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?

Why does this View display a dark background when set to Light Style?

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.

In iOS, is there any standard mechanism for color pickers?

I'm at a loss trying to find anything relevant to this question. Basically, I'm looking to write an app that's kind of like a color picker / swatch library (but with a certain purpose in mind) and I'd like to be able to use it in virtually any app that deals with color selection. Is there any built in, or perhaps novel way, I could either modify some config variable, or send some kind of signal that updates the current color? Or I guess the real question would be, is there any concept of a global color in iOS?
Maybe you are referring to tintColor?
From Apple guidelines:
Using Tint Color
In iOS 7, tint color is a property of UIView. iOS 7 apps often use a
tint to define a key color that indicates interactivity and selection
state for UI elements throughout the app.
When you specify a tint for a view, the tint is automatically
propagated to all subviews in the view’s hierarchy. Because UIWindow
inherits from UIView, you can specify a tint color for the entire app
by setting the window’s tint property using code like this:
window.tintColor = [UIColor purpleColor];
From Apple docs:
The first nondefault tint color value in the view’s hierarchy,
ascending from and starting with the view itself.
I hope that helps.

How to prevent using UIAppearance with UIView's tintColor from changing all UITabBar icon colours?

If I perform UIView.appearance().tintColor = ... the tintColor of all the icons in the tab bar change from the normal inactive grey state to whatever I set the tint color to.
I don't understand why this is the case. I'm just changing the tint color of the app, and by default the tint color doesn't mess with making all the tab bar icons look active at once.
How do I stop it from doing this? I want the tint color to change, but the unselected tabs to retain an inactive color.
I hope you've found a solution by now, but here's my two cents anyway.
Interface Builder doesn't use the UIAppearance API anywhere (as far as I am aware). It does, however, set properties on certain objects, to be applied to them as they're instantiated.
There is a "Global Tint" property in the File Inspector which controls the top-level default tintColor. It is worth noting that, unless explicitly told a different color to use (whether via UIView.appearance() or just UIView.tintColor) child views inherit their tintColor from their parent views. Remember, this chain continues up through the view hierarchy until it hits something that has a tintColor. Usually, it's the UIWindow it ends up hitting, and that has the default blue color of which Apple is so fond. Any dimming or temporary recoloring for state is inherited either from the view itself, or a close ancestor. This is important to note.
It is also good to note that you can respond to this in UIViewController by overriding the tintColorChanged() method, which gets called whenever this happens. By messing with UIView.appearance(), you effectively disable the chain of inheritance for every view in the hierarchy, and you let each fend for itself for its own colors. In my mind, there are at least two ways that this might prevent a UITabBar from properly representing a tab's state:
First, the tab bar has tinted image views under the hood, which inherit their tint color from the parent UITabBar. Even if they could get state-specific colors from the tab bar, the poor thing wouldn't have anything different to tell them, other than, "You were given a color, and you will respect that color!", followed by a slap and a sound flogging, at which point they would sulk back, knowing no more than before. By disabling the hierarchical tintColor inheritance system, you disable state. That's not good. Don't do that.
Second, by setting the tint color for every UIView regardless of state, you have told the tab bar items to hold that color regardless of state. That's not good. Don't do that either.
If you're using Interface Builder (or Storyboards if you prefer), I'd recommend setting that global tint color in the File Inspector, and leaving it at that. This would still set your tint color the way you want, while saving these poor views from domestic abuse.
If you need screenshots of where to find the File Inspector or the Global Tint option, I'd suggest poking around that sidebar on the right in Xcode. A little poking around never hurt anybody (except in movies).
What do you mean when you say you're "changing the tint color of the app"?
The UIView appearance proxy is doing exactly what you told it to. You asked it to set the tintColor of ALL UIViews in your app, which includes those views inside your UITabBar.
It sounds like you don't actually want to alter the tintColor of all UIViews, but instead want to target a specific subset. You should look into appearanceForTraitCollection or the (now deprecated) appearanceWhenContainedIn methods.

Unusually cool looking tab bar setup within a rootviewcontroller of a UISplitView

The ABC (Australian Broadcasting Corporation) iView app for iPad, has great looking tab like setup within a rootViewController of a UISplitView.
The tabs named "Browse/Watch/Listen" are particularly interesting are they simulated or real tabs?
It's unlike any UITabBar I've seen around in iPad apps.
Does anyone know how something like that is possible?
The round rect button in custom mode will be transparent and any png image will maintain in transparencies.
3 or more buttons with transparent images would be the way to go. A different color for when they are selected and your all set. You could also make them look like they are overlapping with images that continue the button next to it.
With the iOS devices it is more about appearance and less about the underlying functionality.
This is a custom control, they made themselves from scratch.
Fortunately for you, you don't need to make it from scratch. :)
There's a lot of open source component that does just this, just like these ones.
Those tabs look and feel like 3 UIButtons. Notice how the UI highlight acts when touching the buttons, and the action is only triggered on touchUpInside.
The tab content is probably a UITableView which gets refreshed when switching tabs.

Resources