Styling Your IOS Application Using Chameleon with the reusable StyleManager in Swift
As an IOS developer, it is hard to manage different type of styles (themes) across an application, requirements are changes, design changes “often”
In developer’s perspective, we have lots of things to customize, such as color sets, patterns, and fonts. So, I have to change in some sets of in globally, maybe some of them specific module/components.
Also, I don’t want to tinker with RGB values, wasting hours figuring out the right color combinations and stop worrying about whether your text will be readable on the various background colors.
I’ve decided to create a manager class to handle them, I had previously flat color patterns in my UIColor+Extensions file, so I give a chance to try Chameleon library.
Chameleon comes with nice and shiny 24 hands picked Flat colors, themes support, and lots of other goods.
So, I’m gisted here the manager. It uses setGlobalThemeUsingPrimaryColor method provided by Chameleon and sets globally primary and secondary color scheme to the application, so primaryTheme and theme functions are the defaults.
Also, we can setup the different theme for UIViewController level, by overriding of course.
- In your AppDelegate after didFinishLaunchingWithOptions initialize StyleManager.setupTheme method.
- Now we can use StyleManager’s methods
self.accountNameLabel.textColor = StyleManager.textTheme()
You can use specific sets such as (i.e tintTheme for your navigationController, textTheme for labels, buttons, backgroudTheme for background colors for your views or for specific alerts positiveTheme, negativeTheme etc) that would help you the manage different types of requirements. You can define your own themes to extend it.
Now it is super-easy to change to any type of colors, fonts or pattern you like to apply, just by configuring the manager, it applies. That’s it.
About the Author
Here is my website, portfolio, and other stuff, so get in touch if you have any questions in mind or drop me an email.
Seyhun Akyürek working as Senior IOS Engineer, writing code using iOS, Swift, Objective-C, Cocoa Touch, Scala, Ruby…seyhunakyurek.com
The latest Tweets from Seyhun AKYÜREK (@seyhunak). Senior Software Engineer IOS, Swift, Objective-C, Rubyist https://t…twitter.com
I hope you liked, have a good dev days :)
Thanks for the reading