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

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.

Related

How to change UIPickerView's selected tint color in iOS 14?

One of iOS 14's changes included changing the UIPickerView to have a light gray selected row tint color. I was wondering if there is any way to change this or even access this property. I looked in the storyboard's attributes inspector and there didn't seem to be anything. Same with the code, autocomplete didn't bring up any selected tint related properties. Also looked around the internet but since it is a relatively new feature there wasn't anything helpful. Before iOS 14 I could put a UIView with my chosen color underneath to simulate this, but this update takes that away as the gray is still visible, and it looks bad. Here's a pic:
https://i.stack.imgur.com/BmoNO.png
I was wondering if there are any real ways to do this.
Also, a good solution would be to disable the light gray, because then I could use the strategy I show above. Any tips?
Without more information I can't say for sure, but in your View Controller class, access the UIPickerView and you can change it's tintColor and isOpaque properties. Something like this I would imagine.
pickerView.isOpaque = false
pickerView.tintColor = .clear
I looked into subviews. On delegate of a UIPickerView, within method didSelectRow I was able to set background.
pickerView.subviews.last?.backgroundColor = .clear

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.

how to create day/night mode for my app

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.

how to change ui componts color according to iOS theme?

I am very new to iOS.I want to set the theme for my iOS app & according to theme i am changing the background image.I also want to change the color of other ui component according to background image.I have one way of doing it by saving value in UserDefaults & check for every UI Component that would be very lengthy process.Is there any kind of other simple way of doing it in iOS?
You can take advantage of appearance proxy. Most of UIKit components have an appearance proxy object.
Let's take for example a navigation bar.
You can have this code.
UIColor *barColor = [UIColor redColor];
[[UINavigationBar appearance] setTintColor:barColor];
Once you execute this, all navigation bars across your app will have a red tint colour. You can customise other things and this way you set your theme globally.

Set the default font style, color, and size for an xcode project

The app I'm working on has a particular color scheme, so I was wondering if it is possible to set a "default" background color, text color, and font size so that every time I create a new view, or label in Interface Builder I don't have to change all of these parameters.
As of iOS 5, there is the UIAppearance protocol that all of the standard UI elements implement. Using the "Appearance proxy" you can set the appearance for ALL objects of that type in a given application. More information can be found in the incredibly helpful and informative WWDC '12 session on "Advanced Appearance Customization on iOS"
How about just creating a DanFViewController (subclassed from UIViewController) that already has the specific background color, text color, font size, etc. you need and then derive all your app's custom views from that?
That's what I do in my own apps where clients are expecting a certain look & feel for all the views.

Resources