主要代码如下:

//自定义导航栏返回按钮
self.navigationItem.leftBarButtonItem = ({ //导航栏返回背景视图
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 44)]; //返回按钮
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 12, 20, 20)];
[button setBackgroundImage:[UIImage imageNamed:@"goBack"]
forState:UIControlStateNormal];
[button addTarget:self
action:@selector(backTo:)
forControlEvents:UIControlEventTouchDown];
button.imageView.contentMode = UIViewContentModeScaleAspectFit;
[view addSubview:button]; //中间分割线
UIView *seprateLine = ({
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(30, 12, 1, 20)];
view.backgroundColor = [UIColor colorWithRed:45/255.0 green:45/255.0 blue:45/255.0 alpha:1];
view;
});
[view addSubview:seprateLine]; //显示返回标题
UILabel *backLabel = ({
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 100, 44)];
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:14];
label.textColor = [UIColor blackColor];
label.text = @"ViewController";
label;
});
[view addSubview:backLabel]; //把view添加上去
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:view];
barButtonItem;
});

Demo代码下载:https://github.com/LuoDaRen/-

iOS 自定义UINavigationController返回按钮的更多相关文章

  1. iOS自定义的UISwitch按钮

    UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...

  2. (ios实战) UINavigationBar 返回按钮 文本自定义实现

    在实际开发过程, 我们使用navigationController时,上一个标题过长,导致下一个界面的返回按钮文本过长,比较难看,如果标题取名过短,又不能完全表达含义. 下面时如何实现返回按钮的Tit ...

  3. 自定义NavgationBa返回按钮

    iOS  上UINavigationController视图压栈形式,可以在当前视图无限制push许多视图,然而一些会觉得自带的push按钮不够美观,而且当上的上一个页面title很长的时候,那个返回 ...

  4. 重写系统中的UINavigationController 返回按钮的事件

    .扩展UIviewController UIViewController+BackButtonHandler.h #import <UIKit/UIKit.h> @protocol Bac ...

  5. 重写系统中的UINavigationController返回按钮的事件

    1.扩展UIviewController UIViewController+BackButtonHandler.h #import <UIKit/UIKit.h> @protocol Ba ...

  6. iOS 自定义NavigationBar右侧按钮rightBarButtonItem

    自定义右侧的一个按钮 UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"主页" style: ...

  7. iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button

    //两个按钮的父类view UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(, , , )]; //历史浏览按钮 ...

  8. 修改UINavigationController返回按钮颜色

    系统默认颜色是蓝色的 视觉效果非常难看 在push进的ViewController中写 //修改UINavigationController的文字颜色 self.navigationControlle ...

  9. ios 自定义NavgationBar的按钮

    UIImage *btnimage = [UIImage imageNamed:@"about.png"]; UIButton *btn = [[UIButton alloc] i ...

随机推荐

  1. 双十一前4小时,CentOS 6.5server启动错误排查

    11月10日晚上8点多.眼看要到双十一了... 但我要说的这段经历却和双十一毫无关系.哈哈. 这天准备向CentOS6.5server的svn上传一些文件,结果开机启动时,却出现了以下的界面: 这是肿 ...

  2. PHP session回收机制(转)

    由于PHP的工作机制,它并没有一个daemon线程,来定时地扫描session信息并判断其是否失效.当一个有效请求发生时,PHP会根据全局变量 session.gc_probability/sessi ...

  3. refresh的停车场(栈和队列的STL)

    refresh的停车场 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述  refresh近期发了一笔横財,开了一家停车场. 因 ...

  4. c# .net Global.asax文件的作用

    1 Global.asax文件的作用 先看看MSDN的解释,Global.asax 文件(也称为 ASP.NET 应用程序文件)是一个可选的文件,该文件包含响应 ASP.NET 或HTTP模块所引发的 ...

  5. linux crontab 定时任务解析

    -----------crontab定时任务---------------------- 检查crontab工具是否安装 crontab -l 检查crontab服务是否启动 service cron ...

  6. uva 12083 Guardian of Decency (二分图匹配)

    uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...

  7. 【React Native开发】React Native控件之RefreshControl组件具体解释(21)

    ),React Native技术交流4群(458982758)种 enabled  bool   android平台适用   用来设置下拉刷新功能是否可用 progressBackgroundColo ...

  8. C# xml读取操作

    以下xml: <Project> <ProjectMains> <ProjectMain Action="added"> <Project ...

  9. KVC基本使用

    首先,创建两个类.person类和book类.如图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/ ...

  10. linux 打印系统时间操作

    版权为个人所有,如需转载请说明出处.(东北大亨) http://www.cnblogs.com/northeastTycoon/p/5511498.html 1. 打开shell脚本 例子1:输出两天 ...