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...
subclass ui elements, , use
myuibutton
instead ofuibutton
, example, orlook @ 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
Post a Comment