zoukankan      html  css  js  c++  java
  • UI2_UINavigationBar

    //
    //  AppDelegate.m
    //  UI2_UINavigationBar
    //
    //  Created by zhangxueming on 15/7/6.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "AppDelegate.h"
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.window.rootViewController];
        self.window.rootViewController = nav;
        
        return YES;
    }
    
    //
    //  ViewController.m
    //  UI2_UINavigationBar
    //
    //  Created by zhangxueming on 15/7/6.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "SubViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        //获取导航条(视图)
        //self.navigationController.navigationBar
        //导航条的高度是44(竖屏)
        //横屏模式高度是32
        NSLog(@"bar = %@", self.navigationController.navigationBar);
        NSLog(@"view = %@", self.view);
        
        //隐藏导航条
        self.navigationController.navigationBar.hidden = YES;
        
        //[self.navigationController setNavigationBarHidden:NO animated:NO];
    }
    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        self.view.backgroundColor = [UIColor cyanColor];
        
        //设置背景图片
        //人像模式(竖屏) UIBarMetricsDefault,
        //风景模式(横屏) UIBarMetricsCompact
        
        //图片命名
        //普通  navigationBar.png
        //高分屏navigationBar@2x.png
        //设置了导航条的背景图片后, 对应的视图控制器的视图的高度被发生变化, 竖屏(0, 64) 横屏(0,32)
        
        self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
        
        self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
        
        self.navigationController.navigationBar.tintColor = [UIColor redColor];
        
        
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar@2x"] forBarMetrics:UIBarMetricsDefault];
        //横屏背景图片
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBarCompact@2x"] forBarMetrics:UIBarMetricsCompact];
        
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
        [btn setTitle:@"按钮" forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
        [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    
    - (void)btnClicked
    {
        SubViewController *svc= [[SubViewController alloc] init];
        [self.navigationController pushViewController:svc animated:YES];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
    
    //
    //  SubViewController.m
    //  UI2_UINavigationBar
    //
    //  Created by zhangxueming on 15/7/6.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import "SubViewController.h"
    
    @interface SubViewController ()
    
    @end
    
    @implementation SubViewController
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        NSLog(@"bar = %@", self.navigationController.navigationBar);
        NSLog(@"view = %@", self.view);
        self.navigationController.navigationBar.hidden = NO;
        
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.view.backgroundColor= [UIColor yellowColor];
    }
    
    - (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
    
  • 相关阅读:
    51nod 1004 n^n的末位数字
    51nod 1003 阶乘后面0的数量
    unity3d-多媒体与网络
    unity3d-代码控制游戏角色控制器移动
    unity3d-角色控制器续
    unity3d-物理引擎
    unity3d-碰撞检测
    unity3d-射线(Ray)
    unity3d-小案例之角色简单漫游
    unity3d-绘制贴图
  • 原文地址:https://www.cnblogs.com/0515offer/p/4638690.html
Copyright © 2011-2022 走看看