用代码创建UITabBarController

本文介绍了一个iOS应用启动时的基本配置流程,包括设置窗口背景颜色、为两个初始视图控制器(FirstViewController和SecondViewController)配置背景图片及标题,并为它们的tabBarItem设置选中与未选中状态的图标,最后将这些视图控制器整合到UITabBarController中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    FirstViewController* first = [[FirstViewController alloc]init];
    //设置背景图片

    first.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"31.png"]];

    //设置tabBarItem选中后的图片与选中前的图片

    [first.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"g1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"nn.png"]];

    //设置标题

    first.title = @"first";


    first.tabBarItem.badgeValue = @"OK";
    
    SecondViewController* second = [[SecondViewController alloc]init];
    second.title = @"second";
    second.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"31.png"]];
    [second.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"g1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"shuijiao.png"]];
    second.tabBarItem.badgeValue = @"OK";
    
    UITabBarController* tc = [[UITabBarController alloc]init];
    tc.viewControllers = [NSArray arrayWithObjects:first,second, nil];
    tc.selectedIndex = 0;
    
    self.window.rootViewController = tc;
    
    [first release];
    [second release];
    
    return YES;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值