iOS学习(UI)知识点整理

一、UINavigationBar 的介绍

1)概念:UINavigationBar 是用于定义导航栏按钮的一个类对象

2)在使用UINavigationBar之前必须先初始化导航栏 实例代码:

 //初始化导航栏
FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:firstVC];
self.window.rootViewController = nav; //appearance一定要在初始化之前使用
//修改默认的UINavigationBar的导航条背景颜色,
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]]; //修改默认的导航栏文字即图标颜色
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; //设置导航栏背景图片
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"icon"] forBarMetrics:UIBarMetricsDefault];

3)setNavigationBarHidden 设置隐藏导航栏  例如:

 [self.navigationController setNavigationBarHidden:YES];

4)title 设置导航栏标题  例如:

 self.title = @“First View”;
//注意:在一处做此设置后,后面的视图控制器如未作设置也会使用此标题

5)titleView 用于设置导航栏中间的视图 例如:

    UIView *navBarView = [[UIView alloc] init];
navBarView.frame = CGRectMake(, , , );
navBarView.backgroundColor = [UIColor clearColor];
navBarView.layer.cornerRadius = 8.0f;
navBarView.clipsToBounds = YES; UIButton *btn1 = [[UIButton alloc] init];
btn1.frame = CGRectMake(, , , );
btn1.backgroundColor = [UIColor blueColor];
[btn1 setTitle:@"消息" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btn1Tapped:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = ;
[navBarView addSubview:btn1]; UIButton *btn2 = [[UIButton alloc] init];
btn2.frame = CGRectMake(, , , );
btn2.backgroundColor = [UIColor blueColor];
[btn2 setTitle:@"电话" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(btn1Tapped:) forControlEvents:UIControlEventTouchUpInside];
btn2.tag = ;
[navBarView addSubview:btn2]; //在导航栏中的中间位置加入我们自定义的view,
//程序会把我们设置的view自动居中
self.navigationItem.titleView = navBarView;

6)UIBarButtonItem 导航栏上的按钮元素  常用的系统自带的Bar有

/*
* UIBarButtonSystemItemDone  按钮样式为文字Done、
* UIBarButtonSystemItemAdd 按钮样式为图片的加号
*UIBarButtonSystemItemCamera 按钮样式是图片的照相机
     
*UIBarButtonSystemItemFixedSpace 是一个占位符 ,可以设置width
*UIBarButtonSystemItemFlexibleSpace 是一个占位符,固定宽度,导航栏上单独一个按钮
*/

例如:

 //系统自带照相机按钮
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self action:@selector(barButtonTapped:)]; //占位符按钮
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:@selector(barButtonTapped:)];

7)rightBarButtonItem 设置导航栏右侧单个按钮 例如:

 self.navigationItem.rightBarButtonItem = button1;

8)rightBarButtonItems 设置导航栏右侧多个按钮 例如:

 self.navigationItem.rightBarButtonItems = @[button2, button1];

9)edgesForExtendedLayout 设置view的坐标都是从导航栏左下点开始计算 防止导航栏遮挡内容区域
例如:

 self.edgesForExtendedLayout = UIRectEdgeNone;

10)initWithTitle 使用文字作为导航栏按钮 例如:

 UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain
target:self action:@selector(back)];

11)initWithImage 使用图片作为导航栏按钮 例如:

 UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"st_logout"] 
style:UIBarButtonItemStylePlain target:self action:@selector(back)];
self.navigationItem.leftBarButtonItem = barButtonItem;

12)setToolbarHidden 设置导航栏显示与隐藏 例如:

  [self.navigationController setToolbarHidden:NO];

13)动画效果实现 代码:

 - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor]; firstView=[[UIView alloc]init];
firstView.frame=CGRectMake(, , , );
firstView.backgroundColor=[UIColor blackColor];
[self.view addSubview:firstView];
for (int i=; i<; i++) {
UIButton *btn=[[UIButton alloc]init];
btn.frame=CGRectMake(,, CGRectGetWidth(self.view.frame), );
}
[self moveFirstViewToRight];
} -(void)moveFirstViewToRight{
//UIview 动画
[UIView animateWithDuration:.f animations:^{
firstView.frame=CGRectMake(self.view.frame.size.width-firstView.frame.size.width, , , );
}];
}
 

iOS阶段学习第31天笔记(UINavigationBar介绍)的更多相关文章

  1. iOS 阶段学习第11天笔记(OC基础知识)

    iOS学习(OC语言)知识点整理 一.OC基础知识 1)#import  用于导入头文件,预处理阶段加载引用,只加载一次. 2)OC 依赖于Foundation框架下的头文件Foundation.h, ...

  2. iOS 阶段学习第七天笔记(函数、递归)

     iOS学习(C语言)知识点整理笔记 一.函数 1)概念:具有特定功能的代码块的封装 2)函数的定义: 函数类型+函数名(形参列表) 函数类型 函数名(形参类型1  形参名1,形参类型2   形参名2 ...

  3. iOS阶段学习第四天笔记(循环)

    iOS学习(C语言)知识点整理笔记 一.分支结构 1.分支结构分为单分支 即:if( ){ } ;多分支 即:if( ){ }else{ }  两种 2.单分支 if表达式成立则执行{ }里的语句:双 ...

  4. iOS阶段学习第三天笔记(运算符)

    iOS学习(C语言)知识点整理笔记 1.运算符 一.算术运算符 1)表达式由变量.常量.运算符构成,有确定的类型和值 2)算术运算符包括: +(加),-(减),*(乘),/(除),%(模) 3)算术运 ...

  5. iOS 阶段学习第四天笔记(循环)

    iOS学习(C语言)知识点整理笔记 一.分支结构 1.分支结构分为单分支 即:if( ){ } ;多分支 即:if( ){ }else{ }  两种 2.单分支 if表达式成立则执行{ }里的语句:双 ...

  6. iOS 阶段学习第三天笔记(运算符)

    iOS学习(C语言)知识点整理笔记 1.运算符 一.算术运算符 1)表达式由变量.常量.运算符构成,有确定的类型和值 2)算术运算符包括: +(加),-(减),*(乘),/(除),%(模) 3)算术运 ...

  7. iOS阶段学习第34天笔记(UI小组件 UISegment-UISlider-UIStepper-UIProgressView-UITextView介绍)

    iOS学习(UI)知识点整理 一.UI小组件 1.UISegmentedControl 分段选择器  实例代码 - (void)viewDidLoad { [super viewDidLoad]; / ...

  8. iOS阶段学习第33天笔记(自定义标签栏(UITabBar)介绍)

    iOS学习(UI)知识点整理 一.自定义标签栏 1.方法一 单个创建标签栏 #import "AppDelegate.h" #import "SecondViewCont ...

  9. iOS阶段学习第32天笔记(页面传值方法介绍)

    iOS学习(UI)知识点整理 一.界面传值方法 1.方法一  Block传值  通过SubView视图的Block向View视图传值改变View视图的背景色 实例代码: 1)SubViewContro ...

随机推荐

  1. [nRF51822] 4、 图解nRF51 SDK中的Schedule handling library 和Timer library

    :nRF51822虽然是一个小型的单片机,但是能真正达到任意调用其官方驱动以及BLE协议栈的人还是奇缺的.据我所见,大都拿官方给的一个冗长的蓝牙低功耗心率计工程改的.之前我对于这个工程进行log跟踪, ...

  2. 如何在JavaScript中正确引用某个方法(bind方法的应用)

    在JavaScript中,方法往往涉及到上下文,也就是this,因此往往不能直接引用,就拿最常见的console.log("info…")来说,避免书写冗长的console,直接用 ...

  3. 实战使用Axure设计App,使用WebStorm开发(1) – 用Axure描述需求

    系列文章 实战使用Axure设计App,使用WebStorm开发(1) – 用Axure描述需求  实战使用Axure设计App,使用WebStorm开发(2) – 创建 Ionic 项目   实战使 ...

  4. Qt QT_BEGIN_NAMESPACE

    问题 阅读Qt的Demo源码的时候,经常在头文件中, 声明类型的部分有以下这样的代码: class MyClassA; ///< 自定义类的声明 QT_BEGIN_NAMESPACE class ...

  5. 网络误区:不用中间变量交换2个变量的value,最高效的是异或运算.

    本文记录了不使用中间变量交换2个变量的value,很多的网络留言说是直接异或运算就可以了,而且效率很高,是真的吗? 这里简单的说一下我的环境:Win7 32位,Qt creator 5.4.1 编译器 ...

  6. Centos 重置密码

    1.在开机启动的时候能看到引导目录,用上下方向键选择你忘记密码的那个系统,然后按“e”. 2.接下来你可以看到如下图所示的画面,然后你再用上下键选择最新的内核,然后在按“e”. 3.执行完上步操作后可 ...

  7. java代码效率优化

    [转载于http://blog.163.com/user_zhaopeng/blog/static/16602270820122105731329/] 1. 尽量指定类的final修饰符 带有fina ...

  8. 基础才是重中之重~Data层如何调用BLL层的方法,如果觉得奇怪请看本文章

    回到目录 看似不伦不类 这个题目有点不伦不类,或者说有点伪模式了,不错,确实是这样,我们正确的开发思维是WEB层->BLL层->DATA层,每个层有对它下层的引用,下层不能引用上层,因为这 ...

  9. spring 学习

    一.spring框架介绍 Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 J2EE 应用程序开发提供 ...

  10. ListView优化为何ViewHolder用static类(转载)

    如果有人还不了解ViewHolder为什么可以起到优化作用,我这边再做下简单说明:Android的findViewById动作是比较耗时的,需要遍历布局的树形结构,才能找到相应的视图.所以如果想在这一 ...