HKViewController.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // HKViewController.m
  3. // HKBaseNavigationDemo
  4. //
  5. // Created by hukaiyin on 16/6/27.
  6. // Copyright © 2016年 hukaiyin. All rights reserved.
  7. //
  8. #import "HKViewController.h"
  9. #import "UIBarButtonItem+Extends.h"
  10. static const int TITLE_BAR_HEIGHT = 44;
  11. @interface HKViewController ()
  12. @property(nonatomic,strong)UIButton *backBtn;
  13. @property(nonatomic,strong)UIButton *rightBtn;
  14. @property(nonatomic,strong)UIButton *leftBtn;
  15. @end
  16. @implementation HKViewController
  17. #pragma mark - Life Cycle
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. [self loadSubViews];
  22. }
  23. - (void)didReceiveMemoryWarning {
  24. [super didReceiveMemoryWarning];
  25. // Dispose of any resources that can be recreated.
  26. }
  27. #pragma mark - Load
  28. - (void)loadSubViews {
  29. self.hidesBottomBarWhenPushed = YES;
  30. self.automaticallyAdjustsScrollViewInsets = NO;
  31. }
  32. #pragma mark - Btn init
  33. - (void)creaBackBtnWithTitle:(NSString *)title {
  34. UIImage *leftBarImage = [UIImage imageNamed:@"nav_back_black"];
  35. self.navigationItem.leftBarButtonItem =
  36. [UIBarButtonItem barItemWithTarget:self
  37. action:@selector(backBtnTUI:)
  38. forControlEvents:UIControlEventTouchUpInside
  39. img:leftBarImage];
  40. }
  41. - (void)creatLeftBtnWithTitle:(NSString *)title {
  42. if (!_leftBtn) {
  43. self.leftBtn = [[UIButton alloc] init];
  44. [self.leftBtn setFrame:CGRectMake(20, 20, TITLE_BAR_HEIGHT, TITLE_BAR_HEIGHT)];
  45. self.leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
  46. [self.leftBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  47. [self.leftBtn setTitle:title forState:UIControlStateNormal];
  48. [self.leftBtn setTitleColor:[UIColor colorWithRed:0.118 green:0.133 blue:0.153 alpha:1.000] forState:UIControlStateNormal];
  49. [self.leftBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  50. [self.leftBtn addTarget:self action:@selector(leftBtnTUI:) forControlEvents:UIControlEventTouchUpInside];
  51. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftBtn];
  52. }
  53. [self.leftBtn setTitle:title forState:UIControlStateNormal];
  54. }
  55. - (void)creaRightBtnWithTitle:(NSString *)title {
  56. if (!_rightBtn) {
  57. self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  58. [self.rightBtn addTarget:self action:@selector(rightBtnTUI:) forControlEvents:UIControlEventTouchUpInside];
  59. [self.rightBtn setTitleColor:[UIColor colorWithRed:0.118 green:0.133 blue:0.153 alpha:1.000] forState:UIControlStateNormal];
  60. self.rightBtn.layer.masksToBounds = YES;
  61. self.rightBtn.layer.cornerRadius = 8;
  62. [self.rightBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  63. }
  64. [self.rightBtn setTitle:title forState:UIControlStateNormal];
  65. [self.rightBtn sizeToFit];
  66. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightBtn];
  67. }
  68. #pragma mark - Btn Methods
  69. - (void)backBtnTUI:(UIButton *)btn {
  70. [self.navigationController popViewControllerAnimated:YES];
  71. }
  72. - (void)leftBtnTUI:(UIButton *)btn; {
  73. }
  74. - (void)rightBtnTUI:(UIButton *)btn {
  75. }
  76. @end