UITabBarController和UINavigationController搭配使用

来源:互联网 发布:网络十大奇书排行 编辑:程序博客网 时间:2024/05/17 07:19

    self.window = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

    

    

    ViewController *vc = [[ViewControlleralloc]init];

    UINavigationController *nvc = [[UINavigationControlleralloc]initWithRootViewController:vc];

    [vc.navigationItemsetTitle:@"第一页"];

    [vc.tabBarItemsetTitle:@"Message"];

    [vc.tabBarItemsetImage:[UIImageimageNamed:@"message.png"]];

    

    [vc.tabBarItemsetBadgeValue:@"99+"];

    //设置字体颜色

    [vc.tabBarItemsetTitleTextAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:20],NSForegroundColorAttributeName:[UIColorwhiteColor]}forState:UIControlStateNormal];

   [vc.tabBarItemsetTitleTextAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:20],NSForegroundColorAttributeName:[UIColorblackColor]}forState:UIControlStateHighlighted];

    [vc.viewsetBackgroundColor:[UIColorblueColor]];

    

    

    SecondViewController *svc = [[SecondViewControlleralloc]init];

    UINavigationController *snvc = [[UINavigationControlleralloc]initWithRootViewController:svc];

    [svc.navigationItemsetTitle:@"第一页"];

    [svc.tabBarItemsetTitle:@"Setting"];

    [svc.tabBarItemsetImage:[UIImageimageNamed:@"setting.png"]];

    [svc.tabBarItemsetBadgeValue:@"999+"];

    [svc.viewsetBackgroundColor:[UIColoryellowColor]];

    

    UITabBarController *tb = [[UITabBarControlleralloc]init];

    tb.viewControllers =@[nvc,snvc];

    [tb.tabBarsetTintColor:[UIColorredColor]];

    [tb.tabBarsetBarTintColor:[UIColororangeColor]];


    

    

    [self.windowsetRootViewController:tb];

    [self.windowmakeKeyAndVisible];

1 0
原创粉丝点击