iOS 自定义UINavigationController返回按钮
主要代码如下:
//自定义导航栏返回按钮
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返回按钮的更多相关文章
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- (ios实战) UINavigationBar 返回按钮 文本自定义实现
在实际开发过程, 我们使用navigationController时,上一个标题过长,导致下一个界面的返回按钮文本过长,比较难看,如果标题取名过短,又不能完全表达含义. 下面时如何实现返回按钮的Tit ...
- 自定义NavgationBa返回按钮
iOS 上UINavigationController视图压栈形式,可以在当前视图无限制push许多视图,然而一些会觉得自带的push按钮不够美观,而且当上的上一个页面title很长的时候,那个返回 ...
- 重写系统中的UINavigationController 返回按钮的事件
.扩展UIviewController UIViewController+BackButtonHandler.h #import <UIKit/UIKit.h> @protocol Bac ...
- 重写系统中的UINavigationController返回按钮的事件
1.扩展UIviewController UIViewController+BackButtonHandler.h #import <UIKit/UIKit.h> @protocol Ba ...
- iOS 自定义NavigationBar右侧按钮rightBarButtonItem
自定义右侧的一个按钮 UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"主页" style: ...
- iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button
//两个按钮的父类view UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(, , , )]; //历史浏览按钮 ...
- 修改UINavigationController返回按钮颜色
系统默认颜色是蓝色的 视觉效果非常难看 在push进的ViewController中写 //修改UINavigationController的文字颜色 self.navigationControlle ...
- ios 自定义NavgationBar的按钮
UIImage *btnimage = [UIImage imageNamed:@"about.png"]; UIButton *btn = [[UIButton alloc] i ...
随机推荐
- MySQL数据表导出某条记录
请按照步骤导出,否则可能会报错: ERROR (HY000): The MySQL server is running with the --secure-file-priv option so it ...
- Cocoapods完整使用篇
温馨提示:在篇文章中所使用的Xcode版本为Xcode7. 一.什么是CocoaPods? 简单来说,就是专门为iOS工程提供对第三方库的依赖的管理工具,通过CocoaPods,我们可以单独管理每 ...
- 这样好用的ReactiveCocoa,根本停不下来【转载】
前戏我个人非常推崇ReactiveCocoa,它就像中国的太极,太极生两仪,两仪生四象,四象生八卦,八卦生万物.ReactiveCocoa是一个高度抽象的编程框架,它真的很抽象,初看你不知道它是要干嘛 ...
- Docker入门系列1:简介
可以实现快速部署. 比如一台 16 核 32G 内存的虚拟机上,需要跑 500+ 个用户的应用(每个应用的功能可以认为是一个网站 + 一系列的 RESTful API),有两个事情很重要: 资源隔离: ...
- 04 redis list结构及命令详解
一:link 链表结构 lpush key value 作用: 把值插入到链接头部[右边] 注意:rpush key value 插入到左边 rpop key 作用: 返回并删除链表尾元素 rpush ...
- Struts2 ModelDriven接口使用
用户在做http请求时一般都有两种方式:get和post方式.get方式用来获取查询相关信息,既向服务器获得信息,而post方式用来更新信息既向服务器提交数据.通常情况下,用get方式向服务器获取信息 ...
- 怎么用cookie解决选项卡问题刷新后怎么保持原来的选项?
什么是cookie? Cookies虽然一般都以英文名呈现,但是它还是有一个可爱的中文名“小甜饼”.Cookies是指服务器暂存放在你的电脑里的txt格式的文本文件资料,主要用于网络服务器辨别电脑使用 ...
- 基础学习笔记之opencv(6):实现将图片生成视频
基础学习笔记之opencv(6):实现将图片生成视频 在做实验的过程中.难免会读视频中的图片用来处理,相反将处理好的图片又整理输出为一个视频文件也是非经常常使用的. 以下就来讲讲基于opencv的C+ ...
- PAT 甲级 1065. A+B and C (64bit) (20) 【大数加法】
题目链接 https://www.patest.cn/contests/pat-a-practise/1065 思路 因为 a 和 b 都是 在 long long 范围内的 但是 a + b 可能会 ...
- debian下烧写stm32f429I discovery裸机程序
需要安装openocd软件.如果已安装默认的openocd,需要先卸载系统默认的openocd(默认版本是0.5.0,版本太低),然后再安装. 在安装前需要安装libusb库文件: -dev libu ...