自定义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

相关文章

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

Java中Switch Case多个条件处理方法举例

《Java中SwitchCase多个条件处理方法举例》Java中switch语句用于根据变量值执行不同代码块,适用于多个条件的处理,:本文主要介绍Java中SwitchCase多个条件处理的相... 目录前言基本语法处理多个条件示例1:合并相同代码的多个case示例2:通过字符串合并多个case进阶用法使用

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

C#TextBox设置提示文本方式(SetHintText)

《C#TextBox设置提示文本方式(SetHintText)》:本文主要介绍C#TextBox设置提示文本方式(SetHintText),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录C#TextBox设置提示文本效果展示核心代码总结C#TextBox设置提示文本效果展示核心代

Pyserial设置缓冲区大小失败的问题解决

《Pyserial设置缓冲区大小失败的问题解决》本文主要介绍了Pyserial设置缓冲区大小失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录问题描述原因分析解决方案问题描述使用set_buffer_size()设置缓冲区大小后,buf

Feign Client超时时间设置不生效的解决方法

《FeignClient超时时间设置不生效的解决方法》这篇文章主要为大家详细介绍了FeignClient超时时间设置不生效的原因与解决方法,具有一定的的参考价值,希望对大家有一定的帮助... 在使用Feign Client时,可以通过两种方式来设置超时时间:1.针对整个Feign Client设置超时时间

Java编译生成多个.class文件的原理和作用

《Java编译生成多个.class文件的原理和作用》作为一名经验丰富的开发者,在Java项目中执行编译后,可能会发现一个.java源文件有时会产生多个.class文件,从技术实现层面详细剖析这一现象... 目录一、内部类机制与.class文件生成成员内部类(常规内部类)局部内部类(方法内部类)匿名内部类二、

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

PyCharm如何设置新建文件默认为LF换行符

《PyCharm如何设置新建文件默认为LF换行符》:本文主要介绍PyCharm如何设置新建文件默认为LF换行符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录PyCharm设置新建文件默认为LF换行符设置换行符修改换行符总结PyCharm设置新建文件默认为LF