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. Unity3D研究院之IOS&Android收集Log文件(六十二)

    开发项目的时候尤其在处理与服务器交互这块,如果服务端程序看不到客户端请求的Log信息,那么无法修改BUG.在Windows上Unity会自动讲Log文件写入本地,但是在IOS和Android上确没有这 ...

  2. PJzhang:最基本的正则表达式实例

    猫宁!!! 参考链接: https://www.cnblogs.com/fozero/p/7868687.html http://tool.oschina.net/regex/# http://too ...

  3. Cannot convert value '0000-00-00 00:00:00' TIMESTAMP

    MySql Timestamp 类型的字段 '0000-00-00 00:00:00'  转换成Java Timestamp 时会抛出 Cannot convert value '0000-00-00 ...

  4. JS中一个new到底做了哪些事情?

    1.https://www.cnblogs.com/faith3/p/6209741.html 2.https://www.cnblogs.com/AaronNotes/p/6529492.html

  5. 最短路之SPFA(单源)HDU 2544

    #include <iostream> #include <queue> #include <algorithm> #define MAXLEN 1005 #def ...

  6. scrapy框架中Download Middleware用法

    scrapy框架中Download Middleware用法   Downloader Middleware处理的过程主要在调度器发送requests请求的时候以及网页将response结果返回给sp ...

  7. bzoj 5449 序列

    https://www.lydsy.com/JudgeOnline/problem.php?id=5449 话说很早以前做过..算是IDA*的板子吧,一个简单的估价函数就可以过去了 %:pragma ...

  8. 洛谷 P4174 [NOI2006]最大获利 && 洛谷 P2762 太空飞行计划问题 (最大权闭合子图 && 最小割输出任意一组方案)

    https://www.luogu.org/problemnew/show/P4174 最大权闭合子图的模板 每个通讯站建一个点,点权为-Pi:每个用户建一个点,点权为Ci,分别向Ai和Bi对应的点连 ...

  9. 工作的时候 用到了 获取时间 DateTime 整理了一下

    获得当前系统时间: DateTime dt = DateTime.Now; Environment.TickCount可以得到“系统启动到现在”的毫秒值 DateTime now = DateTime ...

  10. autofac 遇到构造函数问题

    None of the constructors found with 'aaaaa' on type ' aaa' can be invoked with the available service ...