0

I have a class that I have created to do all the work for customizing appearances. The class is UIAppearance delegate.

UI customization currently affects,

  1. Navigation Bar
  2. Search Bar
  3. Tab bar

All these elements will not vary with Views as I can not forsee a situation where I might have different style for any of those.

Where and How can I place it to be available application wide and such that I don't have to invoke those methods from everywhere (One time call to affect UI tweaks) ?

  • by subclassing ?
  • is AppDelegate a good candidate for this ?
  • importing the subject class and manually invoking the methods

Is it possible to make one time calls for these customizations ?

Kishor Kundan
  • 3,135
  • 1
  • 23
  • 30

2 Answers2

1

You can do this in -applicationDidFinishLaunching.

UIKit classes like UINavigationBar give you an appearance proxy when you call appearance on the class:

[[UINavigationBar appearance] setTintColor:myColor]; sets myColor as the tintColor for all navigation bars.

See the UIAppearance documentation for more details.

mrueg
  • 8,185
  • 4
  • 44
  • 66
  • Yes, I am using UIAppearance proxy. I have background images for all of them. can I really do them in `-applicationDidFinishLaunching` ? That might take the **class in question** out of picture. – Kishor Kundan Mar 24 '13 at 09:34
  • Yes, `applicationDidFinishLaunching` is the right place. You'd want this code to run exactly once each time the app is launched. Additionally, it is good to have all your appearance customization in one place. – mrueg Mar 24 '13 at 10:08
  • What do you mean with class out of picture? – mrueg Mar 24 '13 at 10:09
  • There will not be much point in having a class for few UI customization codes that are basically wrapped in few methods. And if it can be done from `applicationDidFinishLaunching`, the class concept can be dropped. why not just have codes in there ? – Kishor Kundan Mar 24 '13 at 10:15
1

you can use singleTon class like SharedManager, Create all this object in it and it will be available through out your application.

// Step 1: Create a file named "SharedManager.h"

#import <Foundation/Foundation.h>

@interface SharedManager : NSObject
{
    UINavigationBar *navBar;
    UISearchBar *searchBar;
}

@property (nonatomic, retain) UINavigationBar *navBar;
@property (nonatomic, retain) UISearchBar *searchBar;

+(SharedManager *)sharedInstance;

@end

// step 2 : create a file : "SharedManager.m"

#import "SharedManager.h"

static SharedManager *_sharedManager;
@implementation SharedManager

@synthesize navBar , searchBar;

+(SharedManager *)sharedInstance
{
    if(_sharedManager == nil)
    {
        _sharedManager = [[SharedManager alloc] init];

        // Create Navigation Bar
        _sharedManager.navBar = [[UINavigationBar alloc] init];

        // Create Search Bar
        _sharedManager.searchBar = [[UISearchBar alloc] init];
    }

    return _sharedManager;
}

@end

// To access the object use following code, #import "SharedManager.h"

 [[SharedManager sharedInstance].navBar];

it will return object of NavigationBar

Dipen Panchasara
  • 13,480
  • 5
  • 47
  • 57