I have tried in my viewDidLoad:
in my tableview controller, But its changing for only that screen, I need to change for all my screens.
self.myTableView.backgroundColor = [UIColor purpleColor];
myTableView.opaque = NO;
I have tried in my viewDidLoad:
in my tableview controller, But its changing for only that screen, I need to change for all my screens.
self.myTableView.backgroundColor = [UIColor purpleColor];
myTableView.opaque = NO;
Without saving the background color in the user defaults. the background color will reset every time app. get closed. methods to use user defaults:
@implementation Common
+ (id) valueForKey:(NSString *)key
{
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
id val = [NSKeyedUnarchiver unarchiveObjectWithData:data];
return val;
}
+ (id) valueForKey:(NSString *)key defaultValue:(id)default_value
{
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
id val = [NSKeyedUnarchiver unarchiveObjectWithData:data];
if (val)
return val;
[Common setValue:default_value forKey:key];
return default_value;
}
+ (void) setValue:(id)value forKey:(NSString *)key
{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}
@end
In your master view controller. a controller which all controllers subclass:
- (void)viewWillAppear:(BOOL)Animated
{
[super viewWillAppear:Animated];
self.view.backgroundColor = [Common valueForKey:@"BackgroundColor" defaultValue:[UIColor whiteColor]];
}
In your settings page to save the color:
[Common setValue:[UIColor purpleColor] forKey:@"BackgroundColor"];
// or
[Common setValue:[UIColor colorWithRed:10.0/255.0 green:125.0/255.0 blue:95.0/255.0 alpha:1.0] forKey:@"BackgroundColor"];
Note that you need to set your subviews background color to clearColor if needed.
You can merge this solution @Burhanuddin Sunelwala solution to get a perfect one.
1.
Settings
BaseViewController
and let all your ViewControllers inherit from this BaseViewController.viewDidLoad:
orviewWillAppear:
of yourBaseViewController
.Ex:
2.
There is another method by which you can achieve this i.e. Notification Design Pattern
Whenever you change the color in settings, dispatch a notification and receive that notification in your
BaseViewController
.For Saving
If you need to Save the Data so that whenever the user comes back to the application, he sees the last updated color, then you could save it to UserDefaults.