ios - Defining colours programmatically and using them in Interface Builder -


i want customize colours of app reusing same elements changing colours.

these elements simple views, uibutton, uilabel, etc. nothing fancy. colours may come xml or plist preload , parse uicolor.

yes, can create outlet each of them , set them manually, got hundreds of elements , want avoid path.

i tried ibinspectable, without luck, i’m looking widespread solution, views, vcs.

i coding in objective-c way...

could suggest approach on how should this?

comment if want more detailing…

thank much!

couple options...

  1. subclass ui elements, , use myuibutton instead of uibutton, example, or

  2. look @ uiappearance proxy - https://developer.apple.com/reference/uikit/uiappearance - using that, can set default appearance characteristics whole app.

example:

[[uibutton appearance] setbackgroundcolor:[uicolor yellowcolor]]; [[uilabel appearance] setbackgroundcolor:[uicolor orangecolor]]; 

if include 2 lines (often done in appdelegate / didfinishlaunchingwithoptions), every uibutton in app have yellow background, , every uilabel have orange background.

(however, not see these changes in interface builder)


edit:

as charles mentions in comment, can create subclasses , apply appearance changes classes.

suppose have 3 button "types" want apply "color scheme" - dark-blue, medium-blue, light-blue or dark-red, medium-red, light-red, etc. take approach of creating darkuibutton, mediumuibutton , lightuibutton subclasses. then, when load color scheme...

[[darkuibutton appearance] setbackgroundcolor:scheme.darkcolor]; [[mediumuibutton appearance] setbackgroundcolor:scheme.mediumcolor]; [[lightuibutton appearance] setbackgroundcolor:scheme.lightcolor]; 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -