Reputation: 3083
I'm developing a little app and I would like to change the default global tint color from blue to orange. I've seen many ways to do it in Objective-C but I can't seem to get it to work using swift. How could I achieve this? Thanks in advance!
Upvotes: 17
Views: 19033
Reputation: 2639
A small update from Apple here. Tested with Xcode Version 12.4.
There is now an AccentColor
in the Color Asset catalogue which can be set in the build settings. In newer projects it is set by default but older projects might need to add it manually.
AccentColor
" (or whatever you like)
Global Accent Color Name
".
Note that
AccentColor
asset-name is NOT a preserved keyword, and can be anything custom, but the Build setting is what makes this work.Basically,
iOS
has nothing equal to theAndroid
theme yet (2021), where standard colors have keywords, and we can not simply set those in assets.
Upvotes: 14
Reputation: 45220
This answer was last revised for Swift 5.2 and iOS 13.5 SDK.
You can set the tintColor
on your window. Because tint color cascades down to all subviews (unless explicitly overridden), setting it on a window will effectively make it global inside that window.
Add the following line to your application(_:didFinishLaunchingWithOptions:)
or scene(_:willConnectTo:options:)
just before making the window key and visible:
window.tintColor = .systemOrange /* or .orange on iOS < 13 */
You can also set in in the storyboard by changing the Global Tint
property:
Upvotes: 47