123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // SPSBTabBarView.m
- // 我的社保
- //
- // Created by shanp on 2021/4/19.
- //
- #import "SPSBTabBarView.h"
- #import "SPSBUIGeneralHeader.h"
- #import <CALayer+JXHShadow.h>
- #define spsb_itemTag 3000
- #define spsb_itemIconTag 4000
- #define spsb_itemTipsViewTag 6000
- @interface SPSBTabBarView () {
- SPSBTabBarType _currentTab;
- }
- @end
- @implementation SPSBTabBarView
- - (instancetype)init {
- self = [super init];
- if (!self) return nil;
- self.backgroundColor = spsb_FFFFFF_color(1.F);
- [self setTabBarItems];
- return self;
- }
- - (void)chooseTabBar:(SPSBTabBarType)type {
- [self clickAction:[self viewWithTag:type + spsb_itemTag]];
- }
- - (void)tipsViewHidden:(bool)hidden tips:(nullable NSString *)tips tabBarType:(SPSBTabBarType)type {
- UIView *view = [[self viewWithTag:type + spsb_itemTag] viewWithTag:spsb_itemTipsViewTag];
- view.hidden = hidden;
- if (!hidden) {
- UILabel *label = [view viewWithTag:spsb_numberTipsViewLabelTag];
- label.text = tips;
- }
- }
- - (void)clickAction:(UIButton *)sender {
- SPSBTabBarType newTab = sender.tag - spsb_itemTag;
- if (newTab == _currentTab) {
- if (_spsb_tabbarDelegate && [_spsb_tabbarDelegate respondsToSelector:@selector(tabBar:clickSameType:)]) {
- [_spsb_tabbarDelegate tabBar:self clickSameType:_currentTab];
- }
- return;
- }
- UIButton *button = [self viewWithTag:_currentTab + spsb_itemTag];
- button.selected = false;
- _currentTab = sender.tag - spsb_itemTag;
- sender.selected = true;
- if (_spsb_tabbarDelegate && [_spsb_tabbarDelegate respondsToSelector:@selector(tabBar:clickType:)]) {
- [_spsb_tabbarDelegate tabBar:self clickType:_currentTab];
- }
- }
- - (void)setTabBarItems {
- NSArray *titleArray = @[@"首页", @"查询", @"咨询", @"我的"];
- NSArray *imageArray = @[
- jxh_getImage(home_btn_n),
- jxh_getImage(search_btn_n),
- jxh_getImage(consultation_btn_n),
- jxh_getImage(my_btn_n),
- jxh_getImage(home_btn_s),
- jxh_getImage(search_btn_s),
- jxh_getImage(consultation_btn_s),
- jxh_getImage(my_btn_s)
- ];
- NSMutableArray *buttonArray = [@[] mutableCopy];
- CGFloat buttonWidth = jxh_screenWidth() / titleArray.count;
- for (NSInteger i = 0; i < titleArray.count; i ++) {
- JXHCenterButton *button = [JXHCenterButton convenienceWithAxis:JXHCenterButtonAxisVertical interval:3 font:spsb_semiboldFont(10) target:self action:@selector(clickAction:)];
- [button setTitle:titleArray[i] titleColor:spsb_999999_color() state:JXHButtonControlStateNormal];
- [button setTitleColor:spsb_3296FB_color() state:JXHButtonControlStateSelected | JXHButtonControlStateHighlighted | JXHButtonControlStateSelectedAndHighlighted];
- [button setImage:imageArray[i] state:JXHButtonControlStateNormal];
- [button setImage:imageArray[i + titleArray.count] state:JXHButtonControlStateSelected | JXHButtonControlStateHighlighted | JXHButtonControlStateSelectedAndHighlighted];
- button.tag = spsb_itemTag + SPSBTabBarTypeHome + i;
- [self addSubview:button];
- [button makeConstraints:^(JXHConstraintMaker *make) {
- make.top.equalTo(7);
- make.width.equalTo(buttonWidth);
- make.leading.equalTo(buttonWidth * i);
- }];
-
- if (i == titleArray.count - 1) {
- UIView *tipsView = spsb_createNumberTipsViewWithTag(spsb_itemTipsViewTag);
- tipsView.hidden = true;
- [self addSubview:tipsView];
- [tipsView makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(button.centerX).offset(4);
- make.top.equalTo(4);
- }];
- } else {
- UIView *tips = UIView.new;
- tips.backgroundColor = spsb_FF5E5E_color();
- [tips setLayerCornerRadius:4 clipToBounds:false];
- tips.tag = spsb_itemTipsViewTag;
- tips.hidden = true;
- [self addSubview:tips];
- [tips makeConstraints:^(JXHConstraintMaker *make) {
- make.size.equalTo(CGSizeMake(8, 8));
- make.top.equalTo(5);
- make.centerX.equalTo(button.centerX).offset(15);
- }];
- [buttonArray addObject:button];
- }
-
-
- }
- _spsb_buttonArray = buttonArray;
- }
- @end
- #undef spsb_itemTag
- #undef spsb_itemIconTag
- #undef spsb_itemTipsViewTag
|