自定义导航栏(Base)
来源:互联网 发布:如何建立淘宝店铺 编辑:程序博客网 时间:2024/05/16 13:38
+ (void)initialize{ UINavigationBar *bar = [UINavigationBar appearance];// bar.clipsToBounds = YES;// [bar setBackgroundImage:[UIImage imageNamed:@"navigation"] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]]; // 设置整个项目所有item的主题样式 UIBarButtonItem *item = [UIBarButtonItem appearance]; // 设置普通状态 // key:NS****AttributeName NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary]; textAttrs[NSForegroundColorAttributeName] = Color(0, 0, 0, 10); textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17.0]; [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal]; [bar setTitleTextAttributes:textAttrs]; // 设置不可用状态 NSMutableDictionary *disableTextAttrs = [NSMutableDictionary dictionary]; disableTextAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:0.7]; disableTextAttrs[NSFontAttributeName] = textAttrs[NSFontAttributeName]; [item setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled]; //设置导航栏字体的颜色 [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: Color(0, 0, 0, 10), NSForegroundColorAttributeName, [UIFont boldSystemFontOfSize:17], NSFontAttributeName, nil]]; 设置导航栏背景的颜色 [[UINavigationBar appearance] setTintColor:Color(0, 0, 0, 10)];}- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack]; }- (UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent;}- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { //只有在二级页面生效 if ([self.navigationController.viewControllers count] == 2) {// self.navigationController.interactivePopGestureRecognizer.delegate = self; } }}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // UIImage* image = [UIImage imageNamed:@"Navigation_backBtn"]; // [item setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];// // [item setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault]; if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = nil; }// [self.navigationItem.backBarButtonItem setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];// [self.navigationItem.backBarButtonItem setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault];}/** * 重写这个方法目的:能够拦截所有push进来的控制器 * * @param viewController 即将push进来的控制器 */- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if (self.viewControllers.count > 0) { // 这时push进来的控制器viewController,不是第一个子控制器(不是根控制器) /* 自动显示和隐藏tabbar */ viewController.hidesBottomBarWhenPushed = YES; /* 设置导航栏上面的内容 */ // 设置左边的返回按钮// viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"Navigation_backBtn" highImageName:@"Navigation_backBtn" target:self action:@selector(back) title:nil]; // self.navigationController.interactivePopGestureRecognizer.delegate = self;// [viewController.navigationItem.backBarButtonItem setBackButtonBackgroundImage:[UIImage imageNamed:@"navigationbar_more"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; // 设置右边的更多按钮// viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(more) image:@"navigationbar_more" highImage:@"navigationbar_more_highlighted"]; } [super pushViewController:viewController animated:animated];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - View rotation- (BOOL)shouldAutorotate { return NO;}- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait;}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait;}- (void)back { // 因为self本来就是一个导航控制器,self.navigationController这里是nil的 [self popViewControllerAnimated:YES];}
0 0
- 自定义导航栏(Base)
- UINavigationBar自定义导航栏
- 导航栏自定义按钮
- 自定义导航栏
- 自定义导航栏UINavigationBar
- 自定义导航栏
- 自定义导航栏按钮
- 自定义添加导航栏
- iOS自定义导航栏
- iOS自定义导航栏
- 导航栏自定义控件
- 代码自定义导航栏
- 自定义顶部导航栏
- 自定义导航栏
- 自定义导航栏
- 自定义导航栏
- android自定义导航栏
- iOS 自定义导航栏
- ganglia no data there was no data available possible reasons
- 升级android studio2.0后, build grade running速度太慢,完美解决!
- ambari server调整IP的经历,部署前一定要检查环境
- hadoop群集设置block副本,对于数据传输很有影响的
- SET FOREIGN_KEY_CHECKS=0;在Mysql中取消外键约束
- 自定义导航栏(Base)
- Linux流量监控-iftop
- iOS-计时器发送验证码
- ambari安装报错Registration with the server failed.
- 配置多数据源及多个的jdbcTemple
- 关于字符编码以及BOM(字节顺序标记(ByteOrderMark))
- CentOS 上 Jenkins 安装
- Linux下Shell编程实现基于Hadoop的ETL(流程篇)
- 设置tr的border-bottom不生效解决