UINavigationBarUINavigationItem是iOS开发中常用的控件。
 

1.设置导航栏标题

self.title = @"iOS开发:iOSDevTip";

2.设置导航栏样式

设置方法:

[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];

UIBarStyle的样式:

typedef NS_ENUM(NSInteger, UIBarStyle) {
UIBarStyleDefault = 0,
UIBarStyleBlack = 1, UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack
UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES
};

UIBarStyleDefault是默认样式,UIBarStyleBlack是黑色不透明。UIBarStyleBlackOpaqueUIBarStyleBlackTranslucent这两个已经废弃了。

如果想设置导航栏透明,可以加上下面这句代码:

self.navigationController.navigationBar.translucent = YES;

3.修改返回按钮title

self.navigationItem.title = @"test";

4.隐藏返回按钮title

比较笨的方法是:

self.navigationItem.title = @"";

还可以这样设置:

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

5.设置leftBarButtonItem

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];

- (void)back:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}

6.左滑返回手势失效了怎么办

如果按上一步设置leftBarButtonItem之后,左滑返回手势就会失效。设置一下UIGestureRecognizerDelegate代理即可:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

UINavgationController的更多相关文章

  1. 将UINavgationController的push改成从左到右

     CATransition* transition = [CATransition animation]; transition.type = kCATransitionPush;        // ...

  2. ios基础篇(十二)——UINavgationController的使用(三)ToolBar

    UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏:设置UINavigationController的toolbarHidden属性可显示UIToolB ...

  3. ios基础篇(十一)——UINavgationController的使用(二)页面切换

    上篇说到了添加UIBarButtonItem,接下来说说界面切换: 1.首先我们在刚才的RootViewController中添加一个按钮用来实现跳转: 打开RootViewController.m( ...

  4. ios基础篇(十)——UINavgationController的使用(一)UIBarButtonItem的添加

    UINavigationController又被成为导航控制器,继承自UIViewController,以栈的方式管理所控制的视图控制器,下面就详细说一下UINavigationController的 ...

  5. iOS UINavgationController、 UINavigationBar、 UINavigationItem关系分析

    一般导航控制器含有4个对象,UINavigationController.UINavigationBar.UIViewController.UINavigationItem. 1:UINavigati ...

  6. UINavigationController

    知识点: 1)UINavigationController 2)UINavigationBar 3)UINavigationItem 4)UIToolBar ===================== ...

  7. 如何让你的App适配iOS7?

    随着苹果在2013年9月18日发布iOS7最新的系统以来,iOS各种设备升级到iOS7的数字就已经不断刷新记录.目前据外界统计iOS7设备装机量已经达到2.5亿部,已占iOS设备的64%.由此可见让自 ...

  8. Ios学习之容器的理解

    UInavgationController 和 UITabbarController 都是容器 1:uinavigationcontroller (导航控制器) uinavigationcontrol ...

  9. 你真的了解UINavigationController吗?

    一:首先查看一下关于UINavigationController的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : ...

随机推荐

  1. C - Brackets

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...

  2. 大数(string 之间的快速幂)

    //字符串的乘法 string multi(string a, string b){ ], len = a.length() + b.length(); memset(arr, , sizeof ar ...

  3. __next__,__iter__实现迭代器,斐波那契数列

    迭代器__next__,__iter__ 基于__next__和__iter__方法实现的迭代器 class Foo: def __init__(self,n): self.n = n def __i ...

  4. 111 Minimum Depth of Binary Tree 二叉树的最小深度

    给定一个二叉树,找出其最小深度.最小深度是从根节点到最近叶节点的最短路径的节点数量.详见:https://leetcode.com/problems/minimum-depth-of-binary-t ...

  5. ZOJ Course Selection System DP

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5565 Course Selection System Time ...

  6. 自己项目中PHP常用工具类大全分享

    <?php /** * 助手类 * @author www.shouce.ren * */ class Helper { /** * 判断当前服务器系统 * @return string */ ...

  7. HashMap源码及原理

    HashMap 简介 底层数据结构分析 JDK1.8之前 JDK1.8之后 HashMap源码分析 构造方法 put方法 get方法 resize方法 HashMap常用方法测试 感谢 changfu ...

  8. hdu2475Box(splay树形转线性)

    链接 推荐一篇帖子 http://blog.csdn.net/lyhypacm/article/details/6734748 这题暴力不可行主要是因为这颗树可能极度不平衡,不能用并查集是不能路径压缩 ...

  9. bug 查找 (二) 从前端找到后端

    bug 查找 (二) 从前端找到后端 几天来,组长说我们系统的 apm 数据不正确,最体表现就是前端项目这几天错误统计为 0. 这不正常(没有办法,我们代码写的很烂),因为前端环境很复杂,网络,浏览器 ...

  10. Spring Cloud Gateway VS Zuul 比较,怎么选择?

    Spring Cloud Gateway 是 Spring Cloud Finchley 版推出来的新组件,用来代替服务网关:Zuul. 那 Spring Cloud Gateway 和 Zuul 都 ...