TabBarController-demo

本文介绍了一个基于 iOS 的应用程序中使用 UITabBarController 和 UINavigationController 的具体实现方式,包括设置 tabBar 的图片、badge 值及如何通过点击导航栏按钮进行页面跳转。

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

//
//  firstViewController.m
//  TabBarcontroller
//
//  Created by 520 on 15-6-17.
//  Copyright (c) 2015年 520. All rights reserved.
//

#import "firstViewController.h"
#import "SubViewController.h"
@interface firstViewController ()

@end

@implementation firstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
//        self.title=@"First";
//        self.navigationController.navigationBarHidden=NO;
//        self.tabBarItem.badgeValue=@"1";
//        self.tabBarItem.image=[UIImage imageNamed:@"1.png"];
        
        //self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"1.png"] tag:1];
////创建tabBarItem UIImage *im =[UIImage imageNamed:@"1.png"]; self.tabBarItem.badgeValue=@"37+"; self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:im tag:1]; //self.tabBarController.tabBar.selectedImageTintColor = [UIColor orangeColor]; // [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; // [self.view addSubview:im]; // // self.tabBarItem=[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1]; // self.tabBarController.tabBar.selectedItem.selectedImage = [UIImage imageNamed:@"1.png"]; // UITabBarItem *t =[[UITabBarItem alloc] initWithTitle:@"first" image:im tag:1]; // self.tabBarItem=t; // self.tabBarItem.image=im } return self; } - (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage{ } - (void)viewDidLoad { [super viewDidLoad];
////每个页面 UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds]; imageview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;///自适应比例 imageview.image=[UIImage imageNamed:@"011.png"]; [self.view addSubview:imageview]; ////navigationcontroller UIBarButtonItem *rightBaritem=[[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)]; self.navigationItem.rightBarButtonItem=rightBaritem; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)next:(UIBarButtonItem *)barItem{ SubViewController *controller=[[SubViewController alloc] init]; [self.navigationController pushViewController:controller animated:YES]; }
#pargma mark-点击隐藏tabbaritem //// - (void)viewWillAppear:(BOOL)animated{ //[self viewWillAppear:YES]; self.hidesBottomBarWhenPushed=YES; } - (void)viewWillDisappear:(BOOL)animated{ self.hidesBottomBarWhenPushed=NO; } - (void)viewDidDisappear:(BOOL)animated{ //[self viewDidDisappear:YES]; self.hidesBottomBarWhenPushed=NO; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    firstViewController *firstviewcontroller=[[firstViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    
    secondViewController *secondviewcontroller=[[secondViewController alloc] init];
    //UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    thirdViewController *thirdviewcontroller=[[thirdViewController alloc] init];
    //UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    fourViewController *fourviewcontroller=[[fourViewController alloc] init];
   // UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:firstviewcontroller];
    
    NSArray *viewcontrollers=[[NSArray alloc] initWithObjects:nav,secondviewcontroller,thirdviewcontroller,fourviewcontroller, nil];
    UITabBarController *tabBarcontroller = [[UITabBarController alloc] init];
    tabBarcontroller.viewControllers=viewcontrollers;
    tabBarcontroller.selectedIndex=0;
    tabBarcontroller.delegate=self;
        self.window.rootViewController=tabBarcontroller;
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

  

 
 
 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"Second" image:[UIImage imageNamed:@"2.png"] tag:2];
        
       // self.tabBarItem.badgeValue=@"37+";

        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;///自适应比例
    imageview.image=[UIImage imageNamed:@"010.png"];
    [self.view addSubview:imageview];

    // Do any additional setup after loading the view.
}

  

 
 
 
 


#pragma mark-响应navigationcontroller

    UIBarButtonItem *rightBaritem=[[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStyleBordered target:self action:@selector(next:)];

    self.navigationItem.rightBarButtonItem=rightBaritem;

    

  

转载于:https://www.cnblogs.com/deng37s/p/4585557.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值