Skip to content

Commit

Permalink
[iOS][Dark Mode] Change method for setting view default tint color
Browse files Browse the repository at this point in the history
The issue with using UIView.appearance.tintColor is that becomes the
new default, breaking tintColor's inheritance mechanism. In general, if
tintColor is unset, UIKit walks up the view hierarchy until it finds
the nearest set tintColor, and uses that. Now, because tintColor is
set everywhere through UIAppearance, that never happens. In the linked
bug, the close button had a tint set on the UIButton, but not the
contained UIImageView.

This new method sets the tintColor on the root window, so inheritance
still works. If a superview has a provided tintColor, it will apply to
any subviews. For a given view, if it and no ancestors have a
tintColor, the root window will be the closest ancestor and thus the
default.

Bug: 1001501
Change-Id: I06b354e56fd43ec8e171be5b4af4b2e3c7c8bbed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789384
Reviewed-by: Mark Cogan <[email protected]>
Commit-Queue: Robbie Gibson <[email protected]>
Cr-Commit-Position: refs/heads/master@{#694254}
  • Loading branch information
rkgibson2 authored and Commit Bot committed Sep 6, 2019
1 parent e0d22b9 commit a82509a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ios/chrome/browser/ui/appearance/appearance_customization.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#endif

void CustomizeUIAppearance() {
UIView.appearance.tintColor = [UIColor colorNamed:kBlueColor];
// Set fallback tint color for all windows in the app.
for (UIWindow* window in UIApplication.sharedApplication.windows) {
window.tintColor = [UIColor colorNamed:kBlueColor];
}
UISwitch.appearance.onTintColor = [UIColor colorNamed:kBlueColor];
}

0 comments on commit a82509a

Please sign in to comment.