Create uiTabBarController programmatically

前端 未结 4 1487
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 09:23

I want to create a UIView for a UITabBarController

Here is my code for the .h file :

@interface TE : UIViewContro         


        
4条回答
  •  悲&欢浪女
    2021-02-14 09:54

    1. Subclass UITabBarController

    2. Override the - (void) loadView method and include the following code

      MyCustomViewControllerOne* ctrl1 = [[[MyCustomViewControllerOne alloc] initWithNibName@"MyViewControllerOne" bundle: nil] autorelease];
      UIViewController* ctrl2 = [[[UIViewController alloc] init] autorelease];
      MyCustomControllerTwo* ctrl3 = [[[UIViewController alloc] initWithObject: myObj] autorelease];
      
      ctrl1.title = @"First tab";
      ctrl2.title = @"Second tab";
      ctrl3.title = @"Third tab";
      
      ctrl1.tabBarItem.image = [UIImage imageNamed:@"tab_image1.png"];
      ctrl2.tabBarItem.image = [UIImage imageNamed:@"tab_image2.png"];
      ctrl3.tabBarItem.image = [UIImage imageNamed:@"tab_image3.png"];
      
      [self setViewControllers: @[ctrl1, ctrl2, ctrl3]];
      

    That's pretty much it.

提交回复
热议问题