码迷,mamicode.com
首页 > 移动开发 > 详细

iOS Navigation 使用的一些总结

时间:2017-03-17 17:41:56      阅读:399      评论:0      收藏:0      [点我收藏+]

标签:div   iat   hid   alpha   board   ict   ora   animate   led   

1.先说添加吧

  AppDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    // 修改导航颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:100 green:80 blue:50 alpha:1]];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    ViewController *vc = [[ViewController alloc] init];
    self.window.rootViewController = vc;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

2.自定义导航栏

系统自带的方法
//左边按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(selectLeftAction:)];
    self.navigationItem.leftBarButtonItem = leftButton;
    
    //右边按钮
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(selectRightAction2:)];
    self.navigationItem.rightBarButtonItem = rightButton;

自定义按钮图案

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[self scaleToSize:[UIImage imageNamed:@"myselect.png"] size:CGSizeMake(20, 20)] style:UIBarButtonItemStylePlain target:self action:@selector(Actionright:)];





//设置图片大小
- (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(size);
    // 绘制改变大小的图片
    [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
    // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    // 返回新的改变大小后的图片
    return scaledImage;
}

设置push返回按钮的样式

 //push返回按钮样式
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    //self.navigationController.navigationBar.tintColor = [UIColor grayColor];

自定义标题与导航栏的样式

//修改导航栏标题字体大小和颜色,背景颜色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:212/255.0 green:51/255.0 blue:36/255.0 alpha:1]];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{
                                                                      NSFontAttributeName:[UIFont systemFontOfSize:17],
                                                                      NSForegroundColorAttributeName:[UIColor whiteColor]
                                                                      
                                                                      }];

技术分享

这是改变最上边电量图标,时间等颜色

 

3.关于跳转的一些总结:

(1).push跳转到下一页,会带着自己导航栏一起跳,这里说的导航栏说的是他自定义的导航栏的属性

NextViewController *next =[[NextViewController alloc]init];
    [self.navigationController pushViewController:next animated:NO];

(2).push跳转到下一页,下一页隐藏导航栏

//隐藏导航栏
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = YES;
}

(3).pop到前面的任何一页面

//返回视图根控制器
    [self.navigationController popToRootViewControllerAnimated:YES];

//pop到指定页面
//    for (UIViewController *controller in self.navigationController.viewControllers) {
//        if ([controller isKindOfClass:[NextViewController class]]) {
//            NextViewController *A =(NextViewController *)controller;
//            [self.navigationController popToViewController:A animated:YES];
//        }
//    }

//其中的NextViewController为想要跳转到的view

(4).present不带导航栏的跳转

HomeViewController *home = [[HomeViewController alloc]init];
    
    [self presentViewController:home animated:YES completion:^{
        
        NSLog(@"Login Success!");
    }];

如果是拖页面的话

HomeViewController *home = [self.storyboard instantiateViewControllerWithIdentifier:@"home"];
    home.sessionID = self.sessionID;
    [self presentViewController:home animated:YES completion:^{
        
        NSLog(@"Login Success!");
    }];

 

iOS Navigation 使用的一些总结

标签:div   iat   hid   alpha   board   ict   ora   animate   led   

原文地址:http://www.cnblogs.com/qiyiyifan/p/6567461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!