ios学习(自定义导航栏)

自定义导航栏:

1.改变的是所有导航栏的背景颜色

[[UINavigationBar appearance]setBarTintColor:[UIColor yellowColor]];

2.首先要改变导航条背景颜色(里面返回按钮,或者字体的颜色(back))设置的是全局的,所有的页面都是

[[UINavigationBar appearance]setTintColor:[UIColor yellowColor]];

以上两种的设置要在appdelegate中设置

3.隐藏导航栏,在根基视图的基础上设置的,根以后的都会被隐藏 

[self.navigationController setNavigationBarHidden:YES];

4.这种方式设置的标题,只能从根基开始取到,子视图结束。其余的视图不变,而且,根基视图的标题默认居中 

self.title = @"hello";

5.narBarView放入导航栏,这个view会被自动居中

self.navigationItem.titleView = navBarView;(这个navBarView是我门创建的view)

6.导航栏上的按钮

在导航栏上建立按钮,类似于button按钮

UIBarButtonItem *buttonRight = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(button:)];

在导航栏右边设置按钮

self.navigationItem.rightBarButtonItem = buttonRight;

在导航栏左边添加按钮

UIBarButtonItem *buttonLeft = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(button:)];

self.navigationItem.leftBarButtonItem = buttonLeft;

7.导航栏上的按钮UIBarButtonItem

     * UIBarButtonSystemItemDone  按钮样式为文字Done

     * UIBarButtonSystemItemAdd 按钮样式为图片的加号

     *UIBarButtonSystemItemCamera 按钮样式是图片的照相机

     

     *UIBarButtonSystemItemFixedSpace 是一个占位符 ,可以设置width

     *UIBarButtonSystemItemFlexibleSpace 是一个占位符,固定宽度,导航栏上单独一个按钮,样式不能用这个

设置导航栏右侧多个按钮

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

8.view的坐标都是从导航栏左下点开始计算

self.edgesForExtendedLayout = UIRectEdgeNone;

使用文字作为导航栏的按钮

    UIBarButtonItem *buttong = [[UIBarButtonItem alloc]initWithTitle:@"return" style:UIBarButtonItemStylePlain target:self action:@selector(button:)];

    self.navigationItem.leftBarButtonItem = buttong;

9.使用图片作为导航栏返回按钮

UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"bb_1a@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button:)];

self.navigationItem.leftBarButtonItem = bar;

10.显示toolbar 

[self.navigationController setToolbarHidden:NO];

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值