Member-only story
iOS theming with tintColor and accentColor
2 min readMay 19, 2020
Making a holistic and integrated experience requires a theme. Changing Colors of all views to support the theme is a hectic process. To avoid code duplication, we use the tintColor Property. In SwiftUI this tint color is renamed to accentColor. In this tutorial, we going to learn both.
tintColor UIKit
- In UIKit tintColor reflects on all controls(like: Button Slider etc) along with templet Image
- A tint color set to parent propagate to all its children. If a children view want to override the tint. it can set different tint.
class ViewController: UIViewController {
@IBOutlet weak var image: UIImageView! //UIImageView have templet image
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var button1: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
button1.tintColor = .green self.view.tintColor = .red // parent tint
}
}
- Global Tint can be set so that all the controls(button, slider, templet image etc) have same color in all Screen.
Using Code, Set the tint to window:
class SceneDelegate…