i want to change the background color, font, size of the application from same app. from single controller i want to change the appearance of all viewcontroller.
views:
73answers:
2You'll have to implement methods in each controller to change whatever you want. Then, you'll have to maintain a list of all of the controllers you want to change(perhaps do this with a NSMutableArray
in [[UIApplication sharedApplication] delegate]
). Then, you'll have to iterate this array and send each controller an appropriate message.
Alternatively, you could have global variables in your program controlling the appearance of each controller, and have the controllers check for these global variables in their viewDidAppear
method.
Keep UIFont
, UIColor
etc. instances in your app delegate, e.g. in the app delegate header:
// MyAppDelegate.h
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
// ...
UIColor *defaultTableBackgroundTint;
}
// ...
@property (nonatomic, retain) UIColor *defaultTableBackgroundTint;
@end
In the application delegate implementation:
// MyAppDelegate.m
@implementation MyAppDelegate
@synthesize defaultTableBackgroundTint;
- (void) applicationDidFinishLaunching:(UIApplication *)application {
// ...
self.defaultTableBackgroundTint = [UIColor clearColor];
}
- (void) dealloc {
[self.defaultTableBackgroundTint release];
// ...
}
// ...
When you need to use it, set up the following macro definition in your application-wide constants file, or (less ideally) set it up in each view controller:
#define UIAppDelegate ((MyAppDelegate *)[UIApplication sharedApplication].delegate)
Then, in your view controllers:
self.tableView.backgroundTint = [UIAppDelegate defaultTableBackgroundTint];
will set your table view's background tint.
If all your view controllers are set up this way, you can change the color, font, size etc. settings at one location in the application delegate. You just recompile and you're done.