ios 自定义导航栏,开启侧滑返回手势
自定义一个常用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 自定义导航栏,开启侧滑返回手势的更多相关文章
- iOS-自定义导航栏后侧滑返回功能失效
iPhone有一个回退按钮在所有的导航条上.这是一个简单的没有文字箭头. 在一开始写项目的时候,就要做好一个准备,导航栏是自定义还是使用系统的,后期有什么改动,有什么比较特殊的需求.当然这些在更改需求 ...
- iOS 自定义导航栏笔记
一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...
- ios之自定义导航栏上的返回按钮
导航栏的按钮,右边的按钮是可以自己随意添加的.但左边的返回按钮怎么定制?你会说,添加一个自己的按钮呗!你可以试试看,这样行不行. 正确的答案是重载UINavigationController类的pus ...
- 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法
边缘的pop返回手势: override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.purple ...
- iOS 自定义导航栏 和状态栏
一.更改状态栏颜色 (StatusBar) 就是比如导航栏是红色的状态栏是绿色的. 要实现这样的效果其实很简单,就是添加一个背景view. 简单的实现过程如下: 1 // 设置导航颜色 可用 2 [s ...
- IOS 自定义导航栏背景
//- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AV ...
- iOS 自定义导航栏
参考链接:https://blog.csdn.net/huanglinxiao/article/details/100537988 demo下载地址:https://github.com/huangx ...
- iOS学习—— UINavigationController的返回按钮与侧滑返回手势的研究
侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了屏幕左上角那个碍眼的back按钮了.之前在网上搜过有关侧滑手势的技术博客,发现大多比较散乱,甚至有很 ...
- IOS 改变导航栏返回按钮的标题
IOS 改变导航栏返回按钮的标题 下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...
随机推荐
- spring MVC--配置注解
<context-param> 作用:该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数 param-name 设定上下文的参数名称.必须是唯一名称 param-value 设定 ...
- codeforces 612D The Union of k-Segments (线段排序)
D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- DFS的简单应用(zoj2110,poj1562)
zoj2110 简单的dfs应用,注意have数组的处理 #include<iostream> #include<cstdio> #include<cstdlib> ...
- ubuntu命令行卸载软件
“apt-get”命令,这是用于管理已安装程序的通用命令. 安装:apt-get install name 卸载:apt-get remove name 卸载并清除配置:apt-get --p ...
- 标准模板库(STL)学习指南之map映射
转载自CSDN博客:http://blog.csdn.net/bat603/article/details/1456141 Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关 ...
- [转]jQuery.extend 函数详解
JQuery的extend扩展方法: Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解. 一.Jquery的扩展方 ...
- 洛谷【P2115】[USACO14MAR]破坏Sabotage
我对二分的理解:https://www.cnblogs.com/AKMer/p/9737477.html 题目传送门:https://www.luogu.org/problemnew/show/P21 ...
- 洛谷 P4546 & bzoj 5020 在美妙的数学王国中畅游 —— LCT+泰勒展开
题目:https://www.luogu.org/problemnew/show/P4546 先写了个55分的部分分,直接用LCT维护即可,在洛谷上拿了60分: 注意各处 pushup,而且 spla ...
- 【转】 Pro Android学习笔记(二七):用户界面和控制(15):FrameLayout
FrameLayout FrameLayout通常只包含一个控件.如果我们在FrameLayout中设置多个控件,则第二个控件会堆叠在第一个控件上面,如此类推,一层一层地叠上去.下面的例子,我们在Fr ...
- BluetoothGetRadioInfo 函数
DWORD BluetoothGetRadioInfo( HANDLE hRadio, PBLUETOOTH_RADIO_INFO pRadioInfo );获取蓝牙设备的信息.参数: hRadio ...