NavigationBarView.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // NavigationBarView.m
  3. // BuguLive
  4. //
  5. // Created by qitewei on 2025/8/13.
  6. // Copyright © 2025 xfg. All rights reserved.
  7. //
  8. #import "NavigationBarView.h"
  9. @implementation NavigationBarView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setupUI];
  15. }
  16. return self;
  17. }
  18. - (void)setupUI {
  19. self.backgroundColor = UIColor.whiteColor;
  20. [self addSubview:self.contentView];
  21. [self.contentView addSubview:self.titleLabel];
  22. [self.contentView addSubview:self.backButton];
  23. [self.contentView addSubview:self.rightButton];
  24. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.top.mas_offset(STATUS_BAR_HEIGHT);
  26. make.left.right.bottom.mas_offset(0);
  27. }];
  28. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.center.mas_offset(0);
  30. }];
  31. [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.width.height.mas_equalTo(32);
  33. make.left.mas_offset(16);
  34. make.centerY.mas_offset(0);
  35. }];
  36. [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.width.height.mas_equalTo(32);
  38. make.right.mas_offset(-16);
  39. make.centerY.mas_offset(0);
  40. }];
  41. }
  42. - (void)onBackButtonClick {
  43. if (self.onBackButtonkAction) {
  44. self.onBackButtonkAction();
  45. }
  46. }
  47. - (void)onRightButtonClick {
  48. if (self.onRightButtonkAction) {
  49. self.onRightButtonkAction();
  50. }
  51. }
  52. - (UIView *)contentView {
  53. if (!_contentView) {
  54. _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
  55. _contentView.backgroundColor = UIColor.whiteColor;
  56. }
  57. return _contentView;
  58. }
  59. - (UILabel *)titleLabel {
  60. if (!_titleLabel) {
  61. _titleLabel = [[UILabel alloc] init];
  62. _titleLabel.textColor = UIColor.blackColor;
  63. _titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
  64. }
  65. return _titleLabel;
  66. }
  67. - (UIButton *)backButton {
  68. if (!_backButton) {
  69. _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
  70. [_backButton setImage:[UIImage imageNamed:@"icon_nav_back"] forState:UIControlStateNormal];
  71. [_backButton addTarget:self action:@selector(onBackButtonClick) forControlEvents:UIControlEventTouchUpInside];
  72. }
  73. return _backButton;
  74. }
  75. - (UIButton *)rightButton {
  76. if (!_rightButton) {
  77. _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  78. [_rightButton setImage:[UIImage imageNamed:@"icon_nav_help"] forState:UIControlStateNormal];
  79. [_rightButton addTarget:self action:@selector(onRightButtonClick) forControlEvents:UIControlEventTouchUpInside];
  80. }
  81. return _rightButton;
  82. }
  83. @end