123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- //
- // TDNavigationBar.m
- // TheoryNetwork
- //
- // Created by tederen on 2019/9/26.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "TDNavigationBar.h"
- @interface TDNavigationBar ()
- @end
- @implementation TDNavigationBar
- //@synthesize backButton2;
- - (instancetype)initNavigationBar
- {
- self = [super init];
- if (self) {
- self.frame = CGRectMake(0,(IS_IPHONEX?40:20), kGXScreenWidth, 44);
-
- [self addSubview:self.backButton];
- [self addSubview:self.backButton2];
-
- [self addSubview:self.titleLabel];
-
- [self addSubview:self.rightButton];
-
- [self addSubview:self.lineVi];
-
-
-
-
- [_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(0);
- make.centerY.equalTo(self);
- make.size.mas_equalTo(CGSizeMake(50, 44));
- }];
- [_backButton2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.backButton.mas_right);
- make.centerY.equalTo(self.backButton);
- make.width.mas_equalTo(19);
- }];
- [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.mas_right).offset(-15);
- make.centerY.equalTo(self);
- }];
- [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self);
- make.left.mas_equalTo(self.backButton2.mas_right).offset(5);
- make.right.mas_equalTo(self.rightButton.mas_left).offset(-5);
- }];
- _backButton2.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
-
- _rightButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
- [_lineVi mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self);
- make.height.mas_equalTo(0.5f);
- }];
- _lineVi.hidden = YES;
- }
- return self;
- }
- - (void)setTitle:(NSString *)titleStr {
- _titleLabel.text = titleStr;
-
- // CGSize titleSize = [_titleLabel sizeThatFits:CGSizeZero];
- // [_titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- // make.size.mas_equalTo(titleSize);
- // }];
- }
- - (void)setNavigationTintType:(NavigationTintType)type {
- if (type == NavigationTintTypeBlack) {
- [self.backButton setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
- [self.backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [self.rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- self.backgroundColor = [UIColor whiteColor];
- self.lineVi.backgroundColor = [UIColor whiteColor];
- } else if (type == NavigationTintTypeWhite) {
- [self.backButton setImage:IMG(@"icon_back_white") forState:UIControlStateNormal];
- [self.backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [self.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- self.backgroundColor = [UIColor blackColor];
- self.lineVi.backgroundColor = [UIColor blackColor];
- }
- }
- - (void)setBackButtonTitle:(NSString *)backStr {
- [_backButton setTitle:backStr forState:UIControlStateNormal];
- CGSize titleSize = [NSString calculateSizeWithString:backStr fontSize:15.f];
- [_backButton mas_updateConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(10+8+titleSize.width, 20));
- }];
- }
- - (void)setRightButtonTitle:(NSString *)rightStr {
- [self addSubview:self.rightButton];
- [_rightButton setTitle:rightStr forState:UIControlStateNormal];
- [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.mas_right);
- make.centerY.equalTo(self);
- }];
- }
- - (void)backButtonTouch {
- if ([self.delegate respondsToSelector:@selector(backButtonAction)]) {
- [self.delegate backButtonAction];
- return;
- }
- [self.viewController.navigationController popViewControllerAnimated:YES];
- }
- - (void)backButtonTouch2:(TDButton *)sender {
- if ([self.delegate respondsToSelector:@selector(backButtonAction2:)]) {
- [self.delegate backButtonAction2:sender];
- return;
- }
- [self.viewController.navigationController popViewControllerAnimated:YES];
- }
- - (void)rightButtonTouch:(TDButton *)sender {
- if ([self.delegate respondsToSelector:@selector(rightButtonAction:)]) {
- [self.delegate rightButtonAction:sender];
- }
- }
- #pragma mark - setter
- - (TDButton *)backButton {
- if (!_backButton) {
- _backButton = [[TDButton alloc] init];
- [_backButton setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
- [[_backButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
- [_backButton addTarget:self action:@selector(backButtonTouch) forControlEvents:UIControlEventTouchUpInside];
- [_backButton setCurrentButtonHotSize:CGSizeZero];
- }
- return _backButton;
- }
- - (TDButton *)backButton2 {
- if (!_backButton2) {
- _backButton2 = [[TDButton alloc] init];
- _backButton2.hidden = YES;
- [_backButton2 setImage:IMG(@"menu_black_icon") forState:UIControlStateNormal];
- [[_backButton2 titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
- [_backButton2 addTarget:self action:@selector(backButtonTouch2:) forControlEvents:UIControlEventTouchUpInside];
- [_backButton2 setCurrentButtonHotSize:CGSizeZero];
- }
- return _backButton2;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.font = [UIFont systemFontOfSize:17.f];
- _titleLabel.textColor = UIColorHex(#333333);
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _titleLabel;
- }
- - (UIView *)lineVi {
- if (!_lineVi) {
- _lineVi = [UIView new];
- _lineVi.backgroundColor = UIColorHex(eeeeee);
- }
- return _lineVi;
- }
- - (TDButton *)rightButton {
- if (!_rightButton) {
- _rightButton = [[TDButton alloc] init];
- [_rightButton addTarget:self action:@selector(rightButtonTouch:) forControlEvents:UIControlEventTouchUpInside];
- [_rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [[_rightButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
- [_rightButton setCurrentButtonHotSize:CGSizeZero];
- _rightButton.hidden = YES;
- }
- return _rightButton;
- }
- @end
|