XMGNavigationViewController.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  21. {
  22. if (self.childViewControllers.count) {
  23. viewController.hidesBottomBarWhenPushed = YES;
  24. UIButton *button = [[UIButton alloc] init];
  25. [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
  26. [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
  27. //button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  28. //[button setTitle:@"返回" forState:UIControlStateNormal];
  29. [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  30. [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
  31. [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
  32. button.bounds = CGRectMake(0, 0, 44, 44);
  33. //button.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
  34. button.titleLabel.font = [UIFont systemFontOfSize:15];
  35. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
  36. }
  37. [super pushViewController:viewController animated:animated];
  38. }
  39. - (void)back
  40. {
  41. [self popViewControllerAnimated:YES];
  42. }
  43. @end