//  AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    CGRect rect = [UIScreen mainScreen].bounds; //屏幕的大小
    UIWindow *w = [[UIWindow alloc]initWithFrame:rect];//新建一个页面  并且让新建的页面充满整个显示屏
    w.backgroundColor = [UIColor redColor]; //把新建的页面的颜色设为红色
    [w makeKeyAndVisible];//把设置的效果显示在页面上
    self.window = w;//使得开始设置的不要马上系统给销毁
    ViewController *v = [[ViewController alloc]init];//新建另一个页面
    UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:v];//初始画导航页面 并建立
    
    UIImage *image = [UIImage imageNamed:@"a"];//将要使用的图片赋值 并创建
    [nav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];//将图片添加到导航页面中
    
    
    nav.view.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:1];//给导航页面设置背景颜色 并用的是三元色来表示
    v.view.backgroundColor = [UIColor orangeColor];//将页面的背景颜色设置为橘红色
    self.window.rootViewController = nav;//把创建好的导航页面在第一个页面上显示
   
    return YES;
}

//  ViewController.m

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()

@end

@implementation ViewController

//视图加载完成后自动调用
- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.title = @"AAA";   //第一种方法 在导航页面显示标签
    self.navigationItem.title = @"AAA";//第二种方法 在导航页面显示标签
    
    //1.
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(didLeftClicked)];//
    
    //2.
    UIImage *img = [UIImage imageNamed:@"back"];//添加图片 并初始化
//    UIBarButtonItem *leftItem2 = [[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStyleDone target:self action:@selector(didLeftClicked)];//
    
    //3. 使用一个自定义的控件作为左边item
//    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];//
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];//创建一个按钮
    [leftBtn setImage:img forState:UIControlStateNormal];//将图片加载在按钮上
    //只有大小有作用
    leftBtn.frame = CGRectMake(0, 0, 40, 40);//按钮的位置大小
    
    UIBarButtonItem *leftItem3 = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];//
    //设置导航条左/右侧按钮
    self.navigationItem.rightBarButtonItems = @[leftItem3];//
    
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];//
    self.navigationItem.titleView = imgView;//
    
    //导航条分为3个部分
    //0. self.navigationController.navigationBar
    //1. self.navigationItem.leftBarButtonItem(s)
    //2. self.navigationItem.rightBarButtonItem(s)
    //3. self.navigationItem.title(View)
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];//创建一个按钮
    //设置不同状态的标题
    [btn setTitle:@"按钮" forState:UIControlStateNormal];//在常态的时候按钮显示为 “按钮”
    [btn setTitle:@"高亮" forState:UIControlStateHighlighted];//在点击按钮时 按钮显示为“高亮”
//    [btn setBackgroundColor:[UIColor redColor]];//第一种方法表示按钮的背景颜色为红色
    btn.backgroundColor = [UIColor redColor];//第二种方法表示 按钮的背景颜色为红色
    
    [btn addTarget:self action:@selector(didClicked) forControlEvents:UIControlEventTouchUpInside];//点击按钮将要执行的方法名还有执行的类型
    btn.frame = CGRectMake(0, 64, 100, 100);//设置位置和大小
    [self.view addSubview:btn];//显示按钮
}

- (void)didLeftClicked//按钮执行的方法
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)didClicked//按钮执行的方法
{
    NSLog(@"%s", __func__);
    
    SecondViewController *viewCtrl = [[SecondViewController alloc] init];//
//    viewCtrl.view.backgroundColor = [UIColor orangeColor];//
//    [self presentViewController:viewCtrl animated:YES completion:nil];//NULL
    
    [self.navigationController pushViewController:viewCtrl animated:YES];//
    //所有被导航控制器管理的页面,都会拥有一个指针navigationController指向所在的导航控制器
    NSLog(@"2: %p", self.navigationController);//
}

@end

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"Second";//在第二个页面中的导航页面标题设置为这个
    
    self.view.backgroundColor = [UIColor purpleColor];//设置页面的背景颜色
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];//设置一个按钮
    [btn setTitle:@"第二个按钮" forState:UIControlStateNormal];//设置一个常规按钮 并命名为第二个按钮
    [btn addTarget:self action:@selector(didClicked:) forControlEvents:UIControlEventTouchUpInside];//这个按钮将执行自己的didclicked方法
    btn.frame = CGRectMake(100, 100, 200, 50);//设置按钮所在页面的位置
    [self.view addSubview:btn];//把设置的按钮加载在页面上
    
    NSLog(@"btn 1: %p", btn);
}

- (void)didClicked:(UIButton *)sender   //按钮需要执行的方法
{
    NSLog(@"%s", __func__);
    NSLog(@"btn 2: %p", sender);
    
    [self.navigationController popViewControllerAnimated:YES];//将要跳转到前一个页面
}

 

ios 导航页面的更多相关文章

  1. 关于ios导航控制器的知识总结

    关于ios导航控制器的知识总结 添加了导航控制器后: 1.一个导航控制器会有一个顶部导航栏navigationbar和一个底部工具栏toolbar,它们是导航控制器navC的属性.且导航栏默认是不隐藏 ...

  2. 在uwp仿IOS的页面切换效果

    有时候我们需要编写一些迎合IOS用户使用习惯的uwp应用,我在这里整理一下仿IOS页面切换效果的代码. 先分析IOS的页面切换.用户使用左右滑动方式进行前进和后退,播放类似于FlipView的切换动画 ...

  3. 阻止iOS中页面弹性回滚,只允许div.phone_body的区块有弹性

    使用说明:只要替换选择器:var selector = '.phone_body'; /** * 阻止iOS中页面弹性回滚,只允许div.scroller的区块有弹性 */ (function () ...

  4. 解决ios双击页面上移问题

    做webapp时,ios有个默认双击事件,会缩放页面,并将当前点击的位置居中到屏幕,本来也没什么,但是当页面中有fixed定位的元素时,这时候你就会神奇的发现,fixed元素所见不所得了! 还有就是页 ...

  5. Visual Studio跨平台开发实战(3) - Xamarin iOS多页面应用程式开发

    原文 Visual Studio跨平台开发实战(3) - Xamarin iOS多页面应用程式开发 前言 在前一篇教学中, 我们学会如何使用Visual Studio 搭配Xcode 进行iOS基本控 ...

  6. iOS 导航栏返回到指定页面的方法和理解

    关于ios中 viewcontroller的跳转问题,其中有一种方式是采用navigationController pushViewController 的方法,比如我从主页面跳转到了一级页面,又从一 ...

  7. Ios导航栏返回到指定的页面

    在自己的项目实现中有这样的一个需求.一般情况下我们的导航栏返回按钮,是上个页面跳转过来,点击返回按钮返回到上来界面.但是在实际需求中有的并不是这么简单的.有的界面返回是只确定的界面.所以当时自己在实现 ...

  8. ios 指定页面禁用第三方键盘,使用系统的键盘

    因为项目需要,需要在添加银行卡和提现页面使用数字键盘, 如果用户没有安装第三方键盘是没啥大问题的,但是如果用户手机安装了第三方的键盘的话,有时候会无法调用起第三方的数字键盘,或者第三方键盘样式不符合, ...

  9. iOS导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

随机推荐

  1. open()的模块

    对文件操作流程: 1.打开文件,得到文件句柄并赋值给一个变量 2.通过句柄对文件进行操作 3.关闭文件 mode can be: *  'r' 只读. * 'w' 写入,如果之前有就覆盖 * 'a' ...

  2. ASCII码对应表chr(num)

    chr(9) tab空格       chr(10) 换行      chr(13) 回车        Chr(13)&chr(10) 回车换行       chr(32) 空格符      ...

  3. css3技巧属性之text-overflow

    text-overflow:clip | ellipsis 默认值:clip 取值: clip: 当对象内文本溢出时不显示省略标记(...),而是将溢出的部分裁切掉. ellipsis: 当对象内文本 ...

  4. chrome pyv8下载

    url: https://code.google.com/archive/p/pyv8/downloads linux命令: $sudo pip install -v pyv8

  5. 黑帽么metasploit

    .Metasploit框架介绍Metasploit升级更新 Metasploit端口扫描 Metasploit SMB 获取系统信息 Metasploit 服务识别 Metasploit 密码嗅探 M ...

  6. ios 软键盘顶起这个页面

    html { overflow: hidden; } ;;;; } ;;; } ;; left: 200px; overflow: auto;} 行内的滚动条.

  7. CSU 1639 队长,我想进集训队!

    水题 #include<cstdio> int main() { int x1, x2, x3, u, h; int n; while (~scanf("%d", &a ...

  8. Android应用程序组件介绍

    应用程序组件是Android应用程序的基本构建单元.每个组件是系统进入你的应用程序的不同入口点.不是所有的组件对于用户都是实际上的入口点,有些是互相依赖的,但是每个组件都有特定的作用——每个都是唯一的 ...

  9. 第七十三节,css盒模型

    css盒模型 学习要点: 1.元素尺寸 2.元素内边距 3.元素外边距 4.处理溢出 本章主要探讨HTML5中CSS盒模型,学习怎样了解元素的外观配置以及文档的整体布局. 一.元素尺寸 CSS盒模型中 ...

  10. 大数据时代之hadoop(三):hadoop数据流(生命周期)

    了解hadoop,首先就需要先了解hadoop的数据流,就像了解servlet的生命周期似的.hadoop是一个分布式存储(hdfs)和分布式计算框架(mapreduce),但是hadoop也有一个很 ...