IOS ---设置导航栏

#import "AppDelegate.h"

#import "FirstViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

    self.firstViewController=[[FirstViewController alloc]init];

    

    self.window.rootViewController=self.firstViewController;

    UINavigationController * nav=[[UINavigationController alloc]initWithRootViewController:self.firstViewController];

    

    [self.window setRootViewController:nav];

    

    [self.window makeKeyAndVisible];

    

    return YES;

}

//=====================================

#import "FirstViewController.h"

#import "SecondViewController.h"

#import "AppDelegate.h"

@interface FirstViewController ()


@end


@implementation FirstViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    [self.navigationController.navigationBar setBarTintColor:[UIColor purpleColor]];//设置navigationbar的颜色

    self.title=@"首页";

    [self.navigationController.navigationBar setTranslucent:YES];//设置navigationbar的半透明

    

  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(cameraStart)];//设置navigationbar左边按钮

    

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRedo target:self action:@selector(toSecond)];//设置navigationbar右边按钮


    

}

- (void)cameraStart {

     UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"退出APP"message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];

    [alert show];

}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex


{

    if(buttonIndex ==0){

    [self exitApplication ];

    }

    

}


- (void)toSecond {

    SecondViewController *second = [[SecondViewController alloc] init];

    [self.navigationController pushViewController:second animated:YES];

}


//退出APP的方法

- (void)exitApplication {

    AppDelegate *app = [UIApplication sharedApplication].delegate;

    UIWindow *window = app.window;

    [UIView animateWithDuration:1.0f animations:^{

        window.alpha = 0;

        window.frame = CGRectMake(0, window.bounds.size.width, 0, 0);

    } completion:^(BOOL finished) {

        exit(0);

    }];

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#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



//=====================================


#import "SecondViewController.h"


@interface SecondViewController ()


@end


@implementation SecondViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    [self.navigationController.navigationBar setHidden:NO];//隐藏导航栏

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值