Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default global tint color in swift

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!

like image 735
José María Avatar asked Aug 02 '14 12:08

José María


People also ask

What is tint color in swift?

tintColor can be set for any individual view to color just one view, for the whole view in your view controller to color all its subviews, or even for the whole window in your application so that all views and subviews are tinted at once.

How do I change the color of a PNG in Swift?

If you are setting the image for a button, just go to attributes inspector and change the button type to system. Then set the image and change the tint color. The color of the image will change.

What is accent color in IOS Swift?

The accent color is a broad theme color applied to views and controls. You can set it at the application level by specifying an accent color in your app's asset catalog. In macOS, SwiftUI applies customization of the accent color only if the user chooses Multicolor under General > Accent color in System Preferences.


2 Answers

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.

  1. Create a Color Asset with the name "AccentColor" (or whatever you like) enter image description here
  2. Go to your Build Settings of your Target and add the name of your color asset as the value for the entry "Global Accent Color Name". enter image description here

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 the Android theme yet (2021), where standard colors have keywords, and we can not simply set those in assets.

like image 85
palme Avatar answered Oct 17 '22 02:10

palme


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:

like image 44
akashivskyy Avatar answered Oct 17 '22 02:10

akashivskyy