iOS - Storyboard - Use a programmatically define color in the configuration palette of storyboard iOS - Storyboard - Use a programmatically define color in the configuration palette of storyboard xcode xcode

iOS - Storyboard - Use a programmatically define color in the configuration palette of storyboard


As of Xcode 9 you can define and name color inside an Asset; just open the asset in Xcode, right-click and select "New Color Set". Once defined, colors can be selected in the storyboard color picker by name or referenced programmatically, for example:

let green = UIColor(named: "MySpecialGreen")


If there is no solution, i think that i need to set all the attributes : color, font, size, programmatically and not in storyboard.

There's no way to vary colors or other attributes in a storyboard scene based on compile-time parameters. Usually, the right way to approach something like this is to use UIAppearance to override the attributes that you want to change. In a nutshell, any class that implements the UIAppearance protocol can provide a proxy object that lets you adjust the traits that class will use. For example, if you want to adjust the navigation bar's color in your app, define myColor conditionally as you've done and then use UINavigationBar's appearance proxy to set the tint color:

[[UINavigationBar appearance] setBarTintColor:myColor];