主要代码如下:

//自定义导航栏返回按钮
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. eeplat开发平台概念理解

    近期在学习eeplat的开发.发现其中有非常多概念实在让人easy忘记,所以谨以此文记录一笔. eeplat的开发文档里说eeplat是元数据驱动的,这个元数据什么意思.在我理解就是后台的数据库里面的 ...

  2. 笔记本中G-Sensor(加速计) M-Sensor 陀螺仪等传感器的区别

    1.G-sensor重力传感器 作用 G-sensor中文是加速度传感器的意思(英文全称是Accelerometer-sensor),它能够感知到加速力的变化,加速力就是当物体在加速过程中作用在物体上 ...

  3. android 自己定义组件随着手指自己主动画圆

    首先自己定义一个View子类: package com.example.androidtest0.myView; import android.content.Context; import andr ...

  4. java 泛型小小的测试题

    判断以下哪种书写时正确的? 1.ArrayList<String> lists = new ArrayList<String>();2.ArrayList<Object& ...

  5. Redis单台的安装部署及集群部署

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集(diff ...

  6. React常用方法手记

    1.Reactjs 如何获取子组件的key值?请问antd中table自定义列render方法怎么获取当前第几列? https://segmentfault.com/q/101000000453235 ...

  7. python读写数据篇

    一.读写数据1.读数据 #使用open打开文件后一定要记得调用文件对象的close()方法.比如可以用try/finally语句来确保最后能关闭文件.file_object = open('thefi ...

  8. LoadRunner性能测试过程/流程

    用LoadRunner进行负载测试的流程通常由五个阶段组成:计划.脚本创建.场景定义.场景执行和结果分析.(1)计划负载测试:定义性能测试要求,例如并发用户的数量.典型业务流程和所需响应时间.(2)创 ...

  9. 【BZOJ2151】种树 双向链表+堆(模拟费用流)

    [BZOJ2151]种树 Description A城市有一个巨大的圆形广场,为了绿化环境和净化空气,市政府决定沿圆形广场外圈种一圈树.园林部门得到指令后,初步规划出n个种树的位置,顺时针编号1到n. ...

  10. 【BZOJ1150】[CTSC2007]数据备份Backup 双向链表+堆(模拟费用流)

    [BZOJ1150][CTSC2007]数据备份Backup Description 你在一家 IT 公司为大型写字楼或办公楼(offices)的计算机数据做备份.然而数据备份的工作是枯燥乏味的,因此 ...