且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式创建uiTabBarController

更新时间:2023-01-15 08:54:41


  1. 子类UITabBarController

  1. Subclass UITabBarController

覆盖 - (void)loadView方法并包含以下代码

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]];


这就是它。