How to set tab bar item title programmatically in objective c?

前端 未结 10 1460
猫巷女王i
猫巷女王i 2021-01-31 15:46

I want to set title to tab item programatically, but it not works. My code is below:

- (IBAction)tab1Click:(id)sender {
    myTabBarController = [[UITabBarContro         


        
10条回答
  •  终归单人心
    2021-01-31 16:11

    first declare UITabBarDelegate

    - (IBAction)tab1Click:(id)sender {
    
        myTabBarController = [[UITabBarController alloc] init]; 
    
        myTabBarController.delegate = self;
    
        view2Controller = [[View2Controller alloc] init]; 
        [view2Controller setTitle:@"title"];
        view3Controller = [[View3Controller alloc] init];  
        deneme = [[ViewController alloc] init];  
        dename.title = @"Dename";
        view2Conreoller.title = @"View2";
        view3Conreoller.title = @"View3";
        myTabBarController.viewControllers = [NSArray arrayWithObjects:deneme, view2Controller,view3Controller, nil]; 
        [self.view addSubview:myTabBarController.view];    
        myTabBarController.selectedIndex=1;
    }
    

    and even you can set tab images using

    view2Controller.tabBarItem.image = [UIImage imageNamed:@"misle.png"];
    

提交回复
热议问题