Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

iphone - how can i create custom tab bar ...add custom images in tab bar (without xib changes)

i have one application in that tab bar is custom and also all image is different colors ...

how can i create tabbar with diffrent colors and also with different images..this tabbar has navigation view.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

i got the answer ....

h file code ...

@interface CustomTabBarController : UITabBarController 
{

}
@end


@interface AroundParisAppDelegate : NSObject <UIApplicationDelegate,UITabBarControllerDelegate> {
 UIImageView *imgTab ,*imghome ,*imgQuiz,*imgtTW, *imgGuest;
IBOutlet CustomTabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic,retain) IBOutlet CustomTabBarController *tabBarController;
-(void)tabBarControllerView;
@end

in m file :---

@synthesize tabBarController;


-(void)tabBarControllerView
{
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.delegate = self;

    Home *firstTabController =[[Home alloc]initWithNibName:@"Home" bundle:nil];

    //-----second Tab   -----//

    quiz *secondTabController = [[quiz alloc]initWithNibName:@"quiz" bundle:nil];


    //------3rd tab--//
    tw *thirdControllerMap = [[tw alloc] initWithNibName:@"tw" bundle:nil];

    //-----4th tab bar--------//
    guest *fourthTabController = [[guest alloc] initWithNibName:@"guest" bundle:nil];


    tabBarController.viewControllers = [NSArray arrayWithObjects:firstTabController, secondTabController,thirdControllerMap,fourthTabController, nil];

    UINavigationController *objnavifirst=[[UINavigationController alloc] initWithRootViewController:firstTabController];
    UINavigationController *objnavisecond=[[UINavigationController alloc] initWithRootViewController:secondTabController];
    UINavigationController *objnavithird=[[UINavigationController alloc] initWithRootViewController:thirdControllerMap];
    UINavigationController *objnavifourth=[[UINavigationController alloc] initWithRootViewController:fourthTabController];

    NSMutableArray *MainNavArray =[[NSMutableArray alloc] init];
    objnavifirst.navigationBarHidden=YES;
    objnavisecond.navigationBarHidden=YES;
    objnavithird.navigationBarHidden=YES;
    objnavifourth.navigationBarHidden=YES;

    [MainNavArray  addObject:objnavifirst];
    [MainNavArray  addObject:objnavisecond];
    [MainNavArray  addObject:objnavithird];
    [MainNavArray  addObject:objnavifourth];

    tabBarController.viewControllers =MainNavArray; 
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible]; 

    imgTab = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320.0,50)];
    imgTab.image=[UIImage imageNamed:@"Bottom-bar.png"];
    tabBarController.tabBar.tag=10;
    [tabBarController.tabBar addSubview:imgTab];

    imghome=[[UIImageView alloc]initWithFrame:CGRectMake(2.0,00.0,76.0,49.0)];
    imghome.image=[UIImage imageNamed:@"home-hover.png"];
    [imgTab addSubview:imghome];

    imgQuiz=[[UIImageView alloc]initWithFrame:CGRectMake(82.0,00.0,76.0,49.0)];
    imgQuiz.image=[UIImage imageNamed:@"quiz.png"];
    [imgTab addSubview:imgQuiz];

    imgtTW=[[UIImageView alloc]initWithFrame:CGRectMake(164.0,00.0,76.0,49.0)];
    imgtTW.image=[UIImage imageNamed:@"twitter.png"];
    [imgTab addSubview:imgtTW];

    imgGuest=[[UIImageView alloc]initWithFrame:CGRectMake(244.0,00.0,76.0,49.0)];
    imgGuest.image=[UIImage imageNamed:@"guest.png"];
    [imgTab addSubview:imgGuest];

    tabBarController.view.hidden = NO;
    tabBarController.selectedIndex = 1;
}


- (void)tabBarController:(UITabBarController *)tabBarControllers didSelectViewController:(UIViewController *)viewController  
{

    NSLog(@"%i",tabBarControllers.selectedIndex);
    if (tabBarControllers.selectedIndex == 0)
    {

        imghome.image=[UIImage imageNamed:@"home-hover.png"];
        imgQuiz.image=[UIImage imageNamed:@"quiz.png"];
        imgtTW.image=[UIImage imageNamed:@"twitter.png"];
        imgGuest.image=[UIImage imageNamed:@"guest.png"];

    }
    else if (tabBarControllers.selectedIndex == 1)
    {

        imghome.image=[UIImage imageNamed:@"home.png"];
        imgQuiz.image=[UIImage imageNamed:@"quiz-hover.png"];
        imgtTW.image=[UIImage imageNamed:@"twitter.png"];
        imgGuest.image=[UIImage imageNamed:@"guest.png"];

    }
    else if (tabBarControllers.selectedIndex == 2)
    {

        imghome.image=[UIImage imageNamed:@"home.png"];
        imgQuiz.image=[UIImage imageNamed:@"quiz.png"];
        imgtTW.image=[UIImage imageNamed:@"twitter-hover.png"];
        imgGuest.image=[UIImage imageNamed:@"guest.png"];

    }
    else if (tabBarControllers.selectedIndex == 3)
    {

        imghome.image=[UIImage imageNamed:@"home.png"];
        imgQuiz.image=[UIImage imageNamed:@"quiz.png"];
        imgtTW.image=[UIImage imageNamed:@"twitter.png"];
        imgGuest.image=[UIImage imageNamed:@"guest-hover.png"];

    }



}

this is full example for add tab bar


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...