XMGNavigationViewController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // XMGNavigationViewController.m
  3. // 备课-百思不得姐
  4. //
  5. // Created by MJ Lee on 15/6/15.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. //
  8. #import "XMGNavigationViewController.h"
  9. @interface XMGNavigationViewController ()
  10. @end
  11. @implementation XMGNavigationViewController
  12. + (void)initialize
  13. {
  14. UIImage *bg = [UIImage imageNamed:@"navigationbarBackgroundWhite4"];
  15. UINavigationBar *bar = [UINavigationBar appearance];
  16. // [bar setTintColor:[UIColor blackColor]];
  17. [bar setBackgroundImage:bg forBarMetrics:UIBarMetricsDefault];
  18. [bar setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:20]}];
  19. }
  20. - (void)viewDidLoad{
  21. [super viewDidLoad];
  22. self.interactivePopGestureRecognizer.delegate= (id)self;
  23. }
  24. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  25. {
  26. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  27. self.interactivePopGestureRecognizer.enabled = NO;
  28. }
  29. if (self.childViewControllers.count) {
  30. viewController.hidesBottomBarWhenPushed = YES;
  31. UIButton *button = [[UIButton alloc] init];
  32. [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
  33. [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
  34. //button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  35. //[button setTitle:@"返回" forState:UIControlStateNormal];
  36. [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  37. [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
  38. [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
  39. button.bounds = CGRectMake(0, 0, 44, 44);
  40. //button.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  41. button.titleLabel.font = [UIFont systemFontOfSize:15];
  42. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
  43. }
  44. [super pushViewController:viewController animated:animated];
  45. }
  46. - (void)back
  47. {
  48. [self popViewControllerAnimated:YES];
  49. }
  50. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
  51. if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  52. navigationController.interactivePopGestureRecognizer.enabled = YES;
  53. }
  54. if (navigationController.viewControllers.count == 1) {
  55. navigationController.interactivePopGestureRecognizer.enabled = NO;
  56. }
  57. }
  58. @end