Search code examples
iphoneiosipaduitabbarcontrolleruitabbar

iOS - Add title image in UITabBarController


I have created a new Tabbed application in iOS 6
But i want to add an image at the top so that it will be same through out my project

in AppDelegate.m file i added this code

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[LMSFirstViewController alloc] initWithNibName:@"LMSFirstViewController" bundle:nil];
    UIViewController *viewController2 = [[LMSSecondViewController alloc] initWithNibName:@"LMSSecondViewController" bundle:nil];
    UIViewController *viewController3 = [[LMSThirdViewController alloc] initWithNibName:@"LMSThirdViewController" bundle:nil];

    **UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 1024)];
    imageView.image=[UIImage imageNamed:@"LMS.jpg"];**


    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3,nil];

    self.window.rootViewController = self.tabBarController;
    **[self.window addSubview:imageView];**
    [self.window makeKeyAndVisible];
    return YES;
}

But it doesn't load any image
What should i do to add image any other way to implement this

Thanks,
Arun.


Solution

  • once check like this it'l work, add subview after calling the [self.window makeKeyAndVisible]; method,previosly what happend you are adding the subview before loading.

    self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];   
        [self.window addSubview:imageView];