How to change dynamically color used in UIStoryboard

隐身守侯 提交于 2019-12-02 12:29:25

问题


I wonder if it's possible to assign a "dynamic" color in storyboard.

Since iOS7 you can use a tintColor and change it programmatically via the tintColor of the keyWindow. But I can't find a way to affect this tintColor to a button background for example. Which could allow me to easily have a way to theme my application.

I thought of a crazy hack by using a category on UIColor and overloading the initializer to swap a specific color and use this color when ever I want a "dynamic color".

Any ideas?


回答1:


I finally found the solution.. (had to wait for the tool to exist :p).

Crayons is an Alcatraz allowing you to re-use some code define color in Storyboard! yeah!

check it out: https://github.com/Sephiroth87/Crayons




回答2:


Using asset catalog colors in Storyboards

Using asset catalog colors in a Storyboard or an Interface Builder file is pretty straightforward. All color fields, including view background colors, label text colors, should display the colors you defined in the asset catalog under the “Named Colors” section.

Now, access it in storyboard in color palettes

Reference: https://blog.zeplin.io/asset-catalog-colors-on-xcode-9-c4fdccc0381a



来源:https://stackoverflow.com/questions/20061040/how-to-change-dynamically-color-used-in-uistoryboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!