How does using dynamic colors in viewDidLoad automatically switch the colors for Dark mode? - ios-darkmode

Per my understanding of the WWDC 2019 video "Implementing Dark Mode in iOS", dynamic colors are resolved using UITraitCollection.current. The updated trait collection is ready only in certain methods such as draw, viewWillLayoutSubviews etc.
So, if I use dynamic colors inside viewDidLoad, for example, the colors should not update automatically upon mode switch. However, they are being updated
Below is my code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .systemBackground
let label = UILabel(frame: CGRect(x: 100, y: 100, width: 100, height: 20))
label.textColor = UIColor.label
label.text = "Label text"
view.addSubview(label)
}
}
The way I switched the mode in the simulator was Settings -> Developer -> Dark appearance. Then I brought my app to the foreground.
How did the color get auto-updated?
Note: I did not test in my device.

The colors you are using, systemBackground and label, are actually dynamic colors that adopt automatically when the trait collection changes. (Ok, under the hood it's more likely that the views that apply the colors react to trait environment changes and re-evaluate the colors.) That's why you don't need to do anything manually when using the system colors.
If you want the same behavior for your own colors, you have two options:
You can create a color set in an asset catalog. In color sets, you can define different colors for different appearances (light & dark mode and high-contrast accessibility colors). You can them get the color by the name of your color set in code (UIColor(named:)) or use them in interface builder.
Alternatively, you can use a dynamic provider block when creating the color in code, where you can determine the actual color based on the trait collection:
let color = UIColor { traitCollection -> UIColor in
switch traitCollection.userInterfaceStyle {
case .light, .unspecified: return .white
case .dark: return .black
}
}

Related

Same theme but different colors to choose from

Finally my app is almost done, and instead switching to others themes I would like to stick to Modern and change only combinations of colors.
My possible option are:
a) Make a copy of Theme to ModernA, ModernB, etc and change Color.js
b) Apply States to colors to select them according to some condition
c) Change them at runtime (if possible)
Which could be my easy and best approach to do it? and a snippet would be really appreciate.
The best way to do this is to create a new theme and reuse the modern theme; for example:
source/class/myapp/MyModern.js:
qx.Theme.define("myapp.MyModern", {
title : "My Modern",
meta : {
color : myapp.MyColor,
decoration : qx.theme.modern.Decoration,
font : qx.theme.modern.Font,
appearance : qx.theme.modern.Appearance,
icon : qx.theme.icon.Tango
}
});
and source/class/myapp/MyColor.js:
qx.Theme.define("myapp.MyColor", {
extend : qx.theme.modern.Color,
colors : {
// Add your custom colour overrides here
}
});
By using the extend keyword in the MyColor class, you will start with the normal Modern colours and can then choose to override colours as you need
Option C is possible by creating an edited Color theme at runtime:
// First, get the current Color theme
var currentcolor = qx.theme.manager.Color.getInstance().getTheme();
// Change any or all color entries. This can be as dynamic as you want. Get a user defined color from a color picker control. Create Shades based off of a primary color, etc.
currentcolor.colors.themePrimary = "#00ffd4"; // Or a value from the ColorPicker widget
// Now define a new Color theme with the updated colors
qx.Theme.define("NewColor",
{
colors : currentcolor.colors
});
// Set the new Color theme (button used below as an example)
button.addListener("execute", function(e) {
qx.theme.manager.Color.getInstance().setTheme(qx.Theme.getByName("NewColor"));
});

How to define contrast colors in extending a palette in Angular Material theme

Angular Material Documentation for theming states the following to extend an existing palette for custom theming-
var neonRedMap = $mdThemingProvider.extendPalette('red', {
'500': '#ff0000',
'contrastDefaultColor': 'dark'
});
In this, if i want to specify which color i want as the contrast using
'contrastLightColors': ['800']
is it possible? Doesn't seem to be working at all. Just defaults to black on giving contrastDefaultColor.
Is defining a whole new custom palette for this the only option?
I can't exactly use color css property since there are icons also that need to take that color. All those icons are web components (Angular 1.5x) so i want a centralised control over the colors.
What should i do?

Change the background color of my Watson Virtual Agent

I've created a bot using Watson Virtual Agent, and I embedded it in my website. Can I change the background color of the chat window so that it matches the other colors on my site?
You can certainly change the colors of the chat widget to match your brand.
In fact, every color that is used in the chat widget is configurable.
To choose your own colors, you can supply your own colors as part of your config object you pass to the IBMChat.init function.
The example below includes the default colors, but replace the hex codes as you see fit.
var config = {};
//set your other config params
config.styles = {
background: '#3d3d3d',
//the main background color
accentBackground: '#AF6EE8',
/*the background for "accent" elements.
These are the attention grabbing elements like a selected button,
or a loading spinner*/
accentText: '#ffffff',
//the text color for the accentBackground
text: '#ffffff',
//default text color
link: '#ffffff',
/*default link color... this should be a color that works both
with the "background" color and the "secondaryBackground" color.*/
secondaryBackground: '#464646',
/*this is the background for elements that get some emphasis,
but not as much as "accent" elements. e.g. An unselected button
or a container box for a widget.*/
secondaryText: '#f7f7f7',
inputBackground: '#464646',
//background color for your form elements, including the main chat input
inputText: '#f7f7f7'
}
IBMChat.init(config);

Keep ios6 disclosure indicator apparence in ios7

The iOS Disclosure Indicator changed appearance in ios7; it's now a faded grey.
Unfortunately, my app has a lot of pages (more than 100) with different sections and background colors. On ios6, there is no problem, but on ios7 the new disclosure indicator is not visible on the background of some sections.
I need a solution, because I don't have the time to change more than 100 page background, and even if I did, if the color disclosure indicator looks okay in ios7, it's not in ios6, and vice-versa.
Set the tintColor of the table view. This will color the disclosure indicator on the cells.
Note that the tintColor property is only available under iOS 7 so code it properly:
if ([self.tableView respondsToSelector:#selector(setTintColor:)]) {
self.tableView.tintColor = ... // the desired color
}
Will it be possible for you to create custom images for ios7, and set the accessoryView of the problem cells in a method such as the data source 'cellForRowAtIndexPath' like below?
if(UIDevice.currentDevice.systemVersion.floatValue >= 7)
{
UIImageView* customDisclosureImageView = [[UIImageView alloc] initWithImage:normalImage];
customDisclosureImageView.highlightedImage = selectedImage;
cell.accessoryView = customDisclosureImageView;
}

Make custom item in UIActivityViewController icon colorful?

I follow the steps in How can I create a custom UIActivity in iOS? It works as expected. It looks like iOS force a metallic look&feel for all custom icons as well as its own "Bookmark", "Print", etc. Anyway to make my icon colorful?
As of iOS 6, it is not possible to do this.
All color data for the UIImage that is returned by UIActivity's activityImage method will be ignored.
In iOS 10, set the activityCategory class property to .share. This will cause the activity icon to appear in color in the top row of the UIActivityViewController.
In your UIActivity subclass:
In iOS 10, set the activityCategory class property to .share. This will cause the activity icon to appear in color in the top row of the UIActivityViewController.
In your UIActivity subclass:
class MyCustomActivity: UIActivity
{
...
override open class var activityCategory: UIActivityCategory
{
get
{
return UIActivityCategory.share;
}
}
...
}

Resources