//
// 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

UI2_UINavigationBar的更多相关文章

随机推荐

  1. 【OC语法快览】四、基础内存管理

    Basic Memory Management                                                           基础内存管理 If you're w ...

  2. Spark SQL - DataFrame

    1 Overview Spark SQL is a Spark module for structured data processing. It provides a programming abs ...

  3. Preventing CSRF in Java web apps---reference

    reference from:http://ricardozuasti.com/2012/preventing-csrf-in-java-web-apps/ Cross-site request fo ...

  4. JSONP 跨域解决办法

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  5. 工作流_JBPM之Helloword

      环境:Eclipse 3.5 + java 6 + MySQL 5.5 + jBPM 4.4   1.建立 Java Project: 2.拷贝 XML配置文件放进工程目录: 3. 建立 JPDL ...

  6. web开发人员须知的web缓存知识–将数据缓存到浏览器端Net实现

    现实中,服务器在向浏览器发送的数据中,一部分数据是不经常更新的,如果能将这部分数据缓存到浏览器端,将会大大降低传输的数据,提高应用的性能.通过Expires策略,可以使用HTTP 协议定义的缓存机制将 ...

  7. PHP 中mysql如何实现事务提交?

    事务就是指对数据库的多次修改,要么全部成功,要么全部失败,不能出现部分修改成功,部分修改失败的情况. PHP下操作mysql数据库要实现事务提交,需注意以下方面: 1, 数据库表存储引擎类型设置为in ...

  8. 友盟分享各平台URL设置

    首先,想要进项友盟分享,需要到各平台去申请ID和KEY 比如想进行微信分享,就到微信开发者平台去创建应用,拿到对应的id和appScreat,然后进行设置: 参考资料

  9. jq使用手册

    jq 使用手册   翻译整理:Young.J 官方网站:http://jquery.com    jQuery是一款同prototype一样优秀js开发库类,特别是对css和XPath的支持,使我们写 ...

  10. React Native教程 - 调用Web API

    react-native官网Fetch介绍:https://facebook.github.io/react-native/docs/network.html#content react-native ...