Search code examples
iosswiftuiswitch

Set default color of UI element


Let's say I wanted to set the default onTintColor globally for all of my UISwitches to red. Is there a way to set it so when I choose "default" color in the storyboard, it will appear red?


Solution

  • You can set appearance from your appDelegate

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        UISwitch.appearance().tintColor = UIColor.blueColor()
        UISwitch.appearance().onTintColor = UIColor.redColor()
        return true
    }