| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // NavigationBarView.m
- // BuguLive
- //
- // Created by qitewei on 2025/8/13.
- // Copyright © 2025 xfg. All rights reserved.
- //
- #import "NavigationBarView.h"
- @implementation NavigationBarView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- self.backgroundColor = UIColor.whiteColor;
- [self addSubview:self.contentView];
- [self.contentView addSubview:self.titleLabel];
- [self.contentView addSubview:self.backButton];
- [self.contentView addSubview:self.rightButton];
-
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(STATUS_BAR_HEIGHT);
- make.left.right.bottom.mas_offset(0);
- }];
-
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_offset(0);
- }];
-
- [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.height.mas_equalTo(32);
- make.left.mas_offset(16);
- make.centerY.mas_offset(0);
- }];
-
- [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.height.mas_equalTo(32);
- make.right.mas_offset(-16);
- make.centerY.mas_offset(0);
- }];
- }
- - (void)onBackButtonClick {
- if (self.onBackButtonkAction) {
- self.onBackButtonkAction();
- }
- }
- - (void)onRightButtonClick {
- if (self.onRightButtonkAction) {
- self.onRightButtonkAction();
- }
- }
- - (UIView *)contentView {
- if (!_contentView) {
- _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
- _contentView.backgroundColor = UIColor.whiteColor;
- }
- return _contentView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.textColor = UIColor.blackColor;
- _titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
- }
- return _titleLabel;
- }
- - (UIButton *)backButton {
- if (!_backButton) {
- _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_backButton setImage:[UIImage imageNamed:@"icon_nav_back"] forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(onBackButtonClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- - (UIButton *)rightButton {
- if (!_rightButton) {
- _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_rightButton setImage:[UIImage imageNamed:@"icon_nav_help"] forState:UIControlStateNormal];
- [_rightButton addTarget:self action:@selector(onRightButtonClick) forControlEvents:UIControlEventTouchUpInside];
- }
- return _rightButton;
- }
- @end
|