Refresh UILabel properties based on settings theme change

72 views Asked by At

I have a custom UILabel class which is used in my mainViewController.

I have a settings screen and based on the colour chosen in the settings screen, all the UILabels used in the mainViewController will have to update the colour chosen.

Lets say my UILabel colour is black in home screen,I go to settings screen and change the colour to white, and when I come back to my home screen I want all the subclassed labels to update the label colour to white.

I want to update this colour in my customUILabel implementation class and not in the mainViewController, as this label is getting used in 100 other places in my application. I need a single point code change to update the colours.

I have tried using setNeedsDisplay in the viewWillAppear of my viewController, It doesn't work!

Any thoughts in getting this implementation working?

1

There are 1 answers

0
AMarones On

When u change the color you set the color's name in NSString and save it in NSUserDefaults.

To save it: NSString *colorName = K_COLOR_RED; [[NSUserDefaults standardUserDefaults] setValue:colorName forKey:K_KEY_COLOR_LABEL];

To retrieve it: [[NSUserDefaults standardUserDefaults] stringForKey:K_KEY_COLOR_LABEL];

The color K_COLOR_RED and K_KEY_COLOR_LABEL must exist in a Global.h!!

This work fine for me!