自定义UINavigationController 标题、左右边按钮 navigationbar 设置多个按钮

本文主要是介绍自定义UINavigationController 标题、左右边按钮 navigationbar 设置多个按钮,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

#import <UIKit/UIKit.h>@interface ILNavigationController : UINavigationController@end
@implementation ILNavigationController#pragma mark 一个类只会调用一次
+ (void)initialize
{// 1.取出设置主题的对象UINavigationBar *navBar = [UINavigationBar appearance];// 2.设置导航栏的背景图片NSString *navigBG = nil;if (VersionNumber_iOS_7) {navigBG = @"DMnavigationBg7.png";}else{navigBG = @"DMnavigationBg6.png";[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;// 1.4.设置导航栏的文字[navBar setTitleTextAttributes:@{UITextAttributeTextColor : kGetColor(26, 26, 26),UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero],UITextAttributeFont : [UIFont systemFontOfSize:18]}];}[navBar setBackgroundImage:[UIImage imageNamed:navigBG] forBarMetrics:UIBarMetricsDefault];// 3.设置导航栏标题颜色为白色[navBar setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor blackColor]}];
}#pragma mark 控制状态栏的样式
/*状态栏的管理:1> iOS7之前:UIApplication2> iOS7开始:交给对应的控制器去管理*/
- (UIStatusBarStyle)preferredStatusBarStyle
{// 白色样式return UIStatusBarStyleDefault;
}- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{if (self.viewControllers.count) {viewController.hidesBottomBarWhenPushed = YES;}[super pushViewController:viewController animated:animated];
}@end//调用自定义的navigation 导航栏
DMJFQListViewController *wall = [[DMJFQListViewController alloc] init];ILNavigationController *navigation = [[ILNavigationController alloc] initWithRootViewController:wall];[self presentViewController:navigation animated:YES completion:Nil];设置导航栏// 导航栏背景[[UINavigationBar appearance] setTintColor:kNavigationBarColor];// 导航栏标题[[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeTextColor:[UIColor whiteColor]}];// 状态栏颜色[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;//中间标题
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
navLabel.text = @"团购详情";
navLabel.textColor = [UIColor whiteColor];
navLabel.font = [UIFont systemFontOfSize:18];
navLabel.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = navLabel;//右边收藏按钮
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 20, 20);
[rightButton setBackgroundImage:LOAD_IMAGE(@"meishoucang") forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(doShouCang) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem;//左边返回按钮
UIButton *fanHuiButton = [UIButton buttonWithType:UIButtonTypeCustom];
fanHuiButton.frame = CGRectMake(0, 0, 30, 40);
[fanHuiButton setBackgroundImage:LOAD_IMAGE(@"fanhuijiantou") forState:UIControlStateNormal];
[fanHuiButton addTarget:self action:@selector(doFanHui) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:fanHuiButton];
self.navigationItem.leftBarButtonItem = leftItem;<pre name="code" class="objc">


navigationBar 上设置多个按钮
<span style="white-space:pre">	</span>UIButton *rightButton1 = [UIButton buttonWithType:UIButtonTypeCustom];rightButton1.frame = CGRectMake(0, 0, 38, 31);[rightButton1 setBackgroundImage:[UIImage imageNamed:@"pl_add_boyou.png"] forState:UIControlStateNormal];[rightButton1 addTarget:self action:@selector(showAddCompanion) forControlEvents:UIControlEventTouchUpInside];UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithCustomView:rightButton1];UIButton *rightButton2 = [UIButton buttonWithType:UIButtonTypeCustom];rightButton2.frame = CGRectMake(0, 0, 41, 35);[rightButton2 setBackgroundImage:[UIImage imageNamed:@"pl_ibo_setter.png"] forState:UIControlStateNormal];[rightButton2 addTarget:self action:@selector(showAddCompanion) forControlEvents:UIControlEventTouchUpInside];UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]initWithCustomView:rightButton2];NSArray *buttonArray = [[NSArray alloc]initWithObjects:saveButton,deleteButton, nil];self.navigationItem.rightBarButtonItems = buttonArray;


                                    

这篇关于自定义UINavigationController 标题、左右边按钮 navigationbar 设置多个按钮的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1011412

相关文章

SpringBoot AspectJ切面配合自定义注解实现权限校验的示例详解

《SpringBootAspectJ切面配合自定义注解实现权限校验的示例详解》本文章介绍了如何通过创建自定义的权限校验注解,配合AspectJ切面拦截注解实现权限校验,本文结合实例代码给大家介绍的非... 目录1. 创建权限校验注解2. 创建ASPectJ切面拦截注解校验权限3. 用法示例A. 参考文章本文

Vite 打包目录结构自定义配置小结

《Vite打包目录结构自定义配置小结》在Vite工程开发中,默认打包后的dist目录资源常集中在asset目录下,不利于资源管理,本文基于Rollup配置原理,本文就来介绍一下通过Vite配置自定义... 目录一、实现原理二、具体配置步骤1. 基础配置文件2. 配置说明(1)js 资源分离(2)非 JS 资

聊聊springboot中如何自定义消息转换器

《聊聊springboot中如何自定义消息转换器》SpringBoot通过HttpMessageConverter处理HTTP数据转换,支持多种媒体类型,接下来通过本文给大家介绍springboot中... 目录核心接口springboot默认提供的转换器如何自定义消息转换器Spring Boot 中的消息

MySQL设置密码复杂度策略的完整步骤(附代码示例)

《MySQL设置密码复杂度策略的完整步骤(附代码示例)》MySQL密码策略还可能包括密码复杂度的检查,如是否要求密码包含大写字母、小写字母、数字和特殊字符等,:本文主要介绍MySQL设置密码复杂度... 目录前言1. 使用 validate_password 插件1.1 启用 validate_passwo

Python批量替换多个Word文档的多个关键字的方法

《Python批量替换多个Word文档的多个关键字的方法》有时,我们手头上有多个Excel或者Word文件,但是领导突然要求对某几个术语进行批量的修改,你是不是有要崩溃的感觉,所以本文给大家介绍了Py... 目录工具准备先梳理一下思路神奇代码来啦!代码详解激动人心的测试结语嘿,各位小伙伴们,大家好!有没有想

Python自定义异常的全面指南(入门到实践)

《Python自定义异常的全面指南(入门到实践)》想象你正在开发一个银行系统,用户转账时余额不足,如果直接抛出ValueError,调用方很难区分是金额格式错误还是余额不足,这正是Python自定义异... 目录引言:为什么需要自定义异常一、异常基础:先搞懂python的异常体系1.1 异常是什么?1.2

Linux中的自定义协议+序列反序列化用法

《Linux中的自定义协议+序列反序列化用法》文章探讨网络程序在应用层的实现,涉及TCP协议的数据传输机制、结构化数据的序列化与反序列化方法,以及通过JSON和自定义协议构建网络计算器的思路,强调分层... 目录一,再次理解协议二,序列化和反序列化三,实现网络计算器3.1 日志文件3.2Socket.hpp

C语言自定义类型之联合和枚举解读

《C语言自定义类型之联合和枚举解读》联合体共享内存,大小由最大成员决定,遵循对齐规则;枚举类型列举可能值,提升可读性和类型安全性,两者在C语言中用于优化内存和程序效率... 目录一、联合体1.1 联合体类型的声明1.2 联合体的特点1.2.1 特点11.2.2 特点21.2.3 特点31.3 联合体的大小1

Go语言使用select监听多个channel的示例详解

《Go语言使用select监听多个channel的示例详解》本文将聚焦Go并发中的一个强力工具,select,这篇文章将通过实际案例学习如何优雅地监听多个Channel,实现多任务处理、超时控制和非阻... 目录一、前言:为什么要使用select二、实战目标三、案例代码:监听两个任务结果和超时四、运行示例五

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统