Wednesday, 7 September 2016

Set Tabbar at Anywhere (Programatically)

Set Tabbar at Anywhere (Programatically)



#import "firstView.h"
#import "SecView.h"
#import "ThirdView.h"

#import "FourthView.h"




-(IBAction)tabbar_Click:(id)sender
{
    firstView *tocViewController = [[firstView allocinitWithNibName:@"firstView"bundle:nil];
    
    SecView *bookmarkViewController = [[SecView allocinitWithNibName:@"SecView"bundle:nil];
    
    ThirdView *searchViewController = [[ThirdView allocinitWithNibName:@"ThirdView"bundle:nil];
    
    FourthView *aboutUsViewController = [[FourthView alloc]initWithNibName:@"FourthView" bundle:nil];
    
    UINavigationController *tocNavigationController = [[UINavigationController alloc]initWithRootViewController:tocViewController];
    UINavigationController *bookmarkNavigationController = [[UINavigationControllerallocinitWithRootViewController:bookmarkViewController];
    UINavigationController *searchNavigationController = [[UINavigationController alloc]initWithRootViewController:searchViewController];
    UINavigationController *aboutUsNavigationController = [[UINavigationControllerallocinitWithRootViewController:aboutUsViewController];
    
    
    [tocNavigationController.tabBarItem setImage:[UIImage imageNamed:@"data.png"]];
    [bookmarkNavigationController.tabBarItem setImage:[UIImageimageNamed:@"bookmark.png"]];
    [searchNavigationController.tabBarItem setImage:[UIImageimageNamed:@"search.png"]];
    [aboutUsNavigationController.tabBarItem setImage:[UIImageimageNamed:@"info.png"]];
    
    [tocNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"data1.png"]];
    [bookmarkNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"bookmark1.png"]];
    [searchNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"search1.png"]];
    [aboutUsNavigationController.tabBarItem setSelectedImage:[UIImageimageNamed:@"info1.png"]];
    
    [tocNavigationController.tabBarItem setTitle:@"Data"];
    [bookmarkNavigationController.tabBarItem setTitle:@"Bookmarks"];
    [searchNavigationController.tabBarItem setTitle:@"Search"];
    [aboutUsNavigationController.tabBarItem setTitle:@"About Us"];
    
    
    [tocNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
    [bookmarkNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
    [searchNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
    [aboutUsNavigationController.tabBarItem setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:
                                                                [UIColor blackColor],NSForegroundColorAttributeName,
                                                                [UIFont boldSystemFontOfSize:12.0],NSFontAttributeNamenil]
                                                      forState:UIControlStateNormal];
    
   


    UITabBarController *tabBarController = [[UITabBarController allocinit];
    [tabBarController setViewControllers:[NSArrayarrayWithObjects:tocNavigationController,bookmarkNavigationController,searchNavigationController,aboutUsNavigationController, nil]];

    UIImage* tabBarBackground = [UIImage imageNamed:@"TabBar-iPhone.png"];
        
    [[UITabBar appearancesetBackgroundImage:tabBarBackground];
    
    tabBarController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    
    
    [self presentModalViewController:tabBarController animated:YES];
    

}

No comments:

Post a Comment