• iOS Navigation 使用的一些总结


    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!");
        }];
  • 相关阅读:
    webpack 构建同时适用于手机和电脑的调试服务器
    自定义事件 js
    浏览器下载本地数据
    .net 获取当前周及根据年和周获取起始结束时间
    实现SQL Server中的切割字符串SplitString函数,返回Table
    WebApi 服务监控
    log4net 记录MVC监控日志
    一致性Hash算法在Redis分布式中的使用
    Redis主从复制配置
    windows平台下redis安装及配置文件介绍
  • 原文地址:https://www.cnblogs.com/qiyiyifan/p/6567461.html
Copyright © 2020-2023  润新知