自定义一个常用ListViewController

.h文件

 #import <UIKit/UIKit.h>

 @interface ListViewController : UIViewController

 -(void)diquButtonClick;

 @end

.m文件

 //
// ListViewController.m
// OuLianWang
//
// Created by allenariel on 15/6/24.
// Copyright (c) 2015年 皇室美家. All rights reserved.
// #import "ListViewController.h"
#import "ZDYTabBarController.h"
#import "GustomViewController.h" @interface ListViewController () @end @implementation ListViewController
-(void)loadView
{
[super loadView];
[self deplyNavigationController];
self.view.backgroundColor=XZColor(, , );
}
- (void)viewDidLoad
{ [super viewDidLoad];
[self deplyNavigationController]; // [self hideTabBar]; }
-(void)viewWillAppear:(BOOL)animated
{ ZDYTabBarController *tabBar=(ZDYTabBarController*)self.navigationController.tabBarController;
tabBar.zqTabBar.hidden=YES; }
-(void)hideTabBar
{
ZDYTabBarController *tabBar=(ZDYTabBarController*)self.navigationController.tabBarController;
tabBar.zqTabBar.hidden=YES;
// self.view.backgroundColor=ZQColor(232, 232, 232); }
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
ZDYTabBarController *tabBar=(ZDYTabBarController*)self.navigationController.tabBarController;
tabBar.zqTabBar.hidden=NO;
} #pragma mark-------配置导航栏 -(void)deplyNavigationController
{
GustomViewController *navi = [GustomViewController new];
self.navigationController.navigationBar.barTintColor=XZColor(,,);
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName:[UIColor whiteColor]}];
UIButton *diqubutton=[UIButton buttonWithType:UIButtonTypeCustom];
[diqubutton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[diqubutton addTarget:self action:@selector(diquButtonClick) forControlEvents:UIControlEventTouchUpInside];
diqubutton.titleLabel.font=[UIFont boldSystemFontOfSize:];
diqubutton.frame=CGRectMake(, ,,);
UIBarButtonItem *leftbutton=[[UIBarButtonItem alloc]initWithCustomView:diqubutton]; // 调整 leftBarButtonItem 在 iOS7 下面的位置
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?:)) {
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -;//这个数值可以根据情况自由变化
self.navigationItem.leftBarButtonItems = @[negativeSpacer, leftbutton];
}
else self.navigationItem.leftBarButtonItem = leftbutton; self.tabBarController.tabBar.hidden=YES;
}
-(void)diquButtonClick
{
[self.navigationController popViewControllerAnimated:YES]; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

自定义GuestomViewController,

.m

 //
// GustomViewController.m
// 暇课
//
// Created by mac on 15/12/16.
// Copyright © 2015年 暇课. All rights reserved.
// #import "GustomViewController.h" @interface GustomViewController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate> @end @implementation GustomViewController - (instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
if (self = [super initWithRootViewController:rootViewController]) {
// 设置navigationBar的背景颜色,根据需要自己设置
self.navigationBar.barTintColor = XZColor(,,);
// 设置navigationBar是否透明,不透明的话会使可用界面原点下移(0,0)点为导航栏左下角下方的那个点
self.navigationBar.translucent = NO;
// 设置navigationBar是不是使用系统默认返回,默认为YES
self.interactivePopGestureRecognizer.enabled = YES;
// 创建一个颜色,便于之后设置颜色使用
UIColor * color = [UIColor whiteColor];
// 设置navigationBar元素的背景颜色,不包括title
self.navigationBar.tintColor = color;
// 设置navigationController的title的字体颜色
NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
self.navigationBar.titleTextAttributes = dict; self.navigationBar.barTintColor=XZColor(,,);
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName:[UIColor whiteColor]}];
UIButton *diqubutton=[UIButton buttonWithType:UIButtonTypeCustom];
[diqubutton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[diqubutton addTarget:self action:@selector(diquButtonClick) forControlEvents:UIControlEventTouchUpInside];
diqubutton.titleLabel.font=[UIFont boldSystemFontOfSize:];
diqubutton.frame=CGRectMake(, ,,);
UIBarButtonItem *leftbutton=[[UIBarButtonItem alloc]initWithCustomView:diqubutton]; // 调整 leftBarButtonItem 在 iOS7 下面的位置
if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?:)) {
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -;//这个数值可以根据情况自由变化
self.navigationItem.leftBarButtonItems = @[negativeSpacer, leftbutton];
}
else self.navigationItem.leftBarButtonItem = leftbutton; self.tabBarController.tabBar.hidden=YES;
} return self;
} //- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
//{
// // fix 'nested pop animation can result in corrupted navigation bar'
// if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// self.interactivePopGestureRecognizer.enabled = NO;
// }
//
// [super pushViewController:viewController animated:animated];
//}
//
//- (void)navigationController:(UINavigationController *)navigationController
// didShowViewController:(UIViewController *)viewController
// animated:(BOOL)animated
//{
// if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
// navigationController.interactivePopGestureRecognizer.enabled = YES;
// }
//} - (void)viewDidLoad {
[super viewDidLoad]; // 为self创建弱引用对象
__weak typeof (self) weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

完成~

ios 自定义导航栏,开启侧滑返回手势的更多相关文章

  1. iOS-自定义导航栏后侧滑返回功能失效

    iPhone有一个回退按钮在所有的导航条上.这是一个简单的没有文字箭头. 在一开始写项目的时候,就要做好一个准备,导航栏是自定义还是使用系统的,后期有什么改动,有什么比较特殊的需求.当然这些在更改需求 ...

  2. iOS 自定义导航栏笔记

    一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...

  3. ios之自定义导航栏上的返回按钮

    导航栏的按钮,右边的按钮是可以自己随意添加的.但左边的返回按钮怎么定制?你会说,添加一个自己的按钮呗!你可以试试看,这样行不行. 正确的答案是重载UINavigationController类的pus ...

  4. 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法

    边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...

  5. iOS 自定义导航栏 和状态栏

    一.更改状态栏颜色 (StatusBar) 就是比如导航栏是红色的状态栏是绿色的. 要实现这样的效果其实很简单,就是添加一个背景view. 简单的实现过程如下: 1 // 设置导航颜色 可用 2 [s ...

  6. IOS 自定义导航栏背景

    //- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AV ...

  7. iOS 自定义导航栏

    参考链接:https://blog.csdn.net/huanglinxiao/article/details/100537988 demo下载地址:https://github.com/huangx ...

  8. iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究

    侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...

  9. IOS 改变导航栏返回按钮的标题

    IOS 改变导航栏返回按钮的标题   下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...

随机推荐

  1. Python基础-修改excel中内容

    from xlutils.copy import copy import xlrd import os #1.打一要修改的excel #2.再打开另一个excel #3.把第一个excel里面修改东西 ...

  2. jspsmartupload 文件上传让input数据和文件上传同时提交

    一.使用原因: 文件上传时,表单的属性中必须要有multipart/form-data,如以下例子: <form name="form_post" class="a ...

  3. 06 - Django应用第三步

    知识点 1) 编写urls 配合include()的URL查找过程 获取正则抓取的值并命名, 给url取名 2) 模板的编写 for循环的遍历 用点的方式执行函数, 不带括号 3) 视图函数的编写 H ...

  4. 【leetcode刷题笔记】Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  5. 【二叉树的递归】06填充每个节点中的下一个正确的指针【Populating Next Right Pointers in Each Node】

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树 struct Tr ...

  6. 【遍历二叉树】04二叉树的层次遍历【Binary Tree Level Order Traversal】

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,返回他的层次遍历的 ...

  7. urllib,urlib2与httplib,urllib3

    urllib:编码参数离不开urllib,urllib.urlencode, urllib.urlopen(URL,[,data]) 支持POST,根据参数区分post或者get urllib2:发送 ...

  8. BZOJ5324 JXOI2018 守卫

    传送门 这是我见过的为数不多的良心九怜题之一 题目大意 给定一段$n$个点构成的折线,第$i$个折点的坐标是$(i,h_i)$,你可以在$i$点放置一个视野,定义$i$能看到$j$当且仅当$i$处有视 ...

  9. Agc010_D Decrementing

    今天本人因调了上篇博客的题而脑壳不适,不想颓题,因此有了这篇博客. 但是博客毕竟得讲点什么,想想有没有什么代码短的. 哦,好像有,就Agc010_D Decrementing好了. Alice和Bob ...

  10. 洛谷【P1601】A+B Problem(高精)

    题目传送门:https://www.luogu.org/problemnew/show/P1601 高精度加法板子.我们灵性地回忆一波小学学加法列竖式的场景(从\(6\)岁开始口算从未打过草稿的大佬请 ...