Search code examples
iphoneiosuitabbaruiappearance

Customize UITabbar via Appearance proxy vs setting the properties directly (Differences, Advantages...)


When customizing an UITabBar I have two ways doing this, both work but I'm curious what's the best approach and what advantages, disadvantages I have with both ways?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        UITabBarController *tbc = (UITabBarController *)self.window.rootViewController;

        UITabBar *tb = tbc.tabBar;

        // 1. Customizing UITabBar using appearance proxy:
        [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar.png"]];
        [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];


        // 2. Doing the same by setting the properties directly:
        // tb.backgroundImage = [UIImage imageNamed:@"tabbar.png"];
        // tb.selectionIndicatorImage = [UIImage imageNamed:@"tabbar_selected.png"];

        return YES;
    }

Solution

  • Advantage of Appearance proxy is you can change the appearance of any controller at any time, or even save some redrawing calls taking advantage of it.

    Any changes you make with a proxy object are applied, at view layout time, to all instances of the class that exist or that are subsequently created. However, you can still override the proxy defaults later using the methods and properties of a given instance.

    For accessing with properties you need an object of that controller and then you can access it. Also you can check this doc