首次提交
This commit is contained in:
124
SweetParty/主类/Others/TabBar/SATabBarVC.m
Executable file
124
SweetParty/主类/Others/TabBar/SATabBarVC.m
Executable file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// SATabBarVC.m
|
||||
// SamaVoice
|
||||
//
|
||||
// Created by 申中迪 on 2022/5/8.
|
||||
//
|
||||
|
||||
#import "SATabBarVC.h"
|
||||
#import "UITabBar+Badge.h"
|
||||
#import "MainNavigationController.h"
|
||||
#import "SPCustomTabBar.h"
|
||||
#import "SPHomeContainerVC.h"
|
||||
#import "SPTrendContainerVC.h"
|
||||
#import "SPPartyListVC.h"
|
||||
#import "TXMessageVC.h"
|
||||
#import "SPMineVC.h"
|
||||
#import "TXMicIMService.h"
|
||||
|
||||
@interface SATabBarVC ()
|
||||
|
||||
@property (nonatomic, strong) SPCustomTabBar *coustomBar;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SATabBarVC
|
||||
|
||||
singleton_implementation(SATabBarVC)
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self updateMsgDot];
|
||||
|
||||
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateMsgDot) name:TXIMUnreadMessageNoti object:nil];
|
||||
}
|
||||
|
||||
- (void)updateMsgDot {
|
||||
[[TXMicIMService sharedService] onGetUnreadCount:^(NSInteger count) {
|
||||
if (count == 0) {
|
||||
[self.tabBar hideBadgeOnItemIndex:2];
|
||||
}else {
|
||||
[self.tabBar showBadgeOnItemIndex:2 color:HEXCOLOR(0xFF5057) withCount:count];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadView {
|
||||
[super loadView];
|
||||
|
||||
// // 自定义中间按钮
|
||||
self.coustomBar = [[SPCustomTabBar alloc] init];
|
||||
|
||||
UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, APPW-30, 50)];
|
||||
bgImg.image = ImageNamed(@"tabbar_backIMG");
|
||||
[self.coustomBar addSubview:bgImg];
|
||||
|
||||
|
||||
[self.coustomBar.centerBtn addTarget:self action:@selector(onSweetParty) forControlEvents:UIControlEventTouchUpInside];
|
||||
// //透明设置为NO,显示白色,view的高度到tabbar顶部截止,YES的话到底部
|
||||
self.coustomBar.translucent = NO;
|
||||
// //利用KVC 将自己的tabbar赋给系统tabBar
|
||||
[self setValue:self.coustomBar forKeyPath:@"tabBar"];
|
||||
|
||||
SPPartyListVC *homeVC = [[SPPartyListVC alloc] init];
|
||||
[self addPropertyToChildVC:homeVC image:[UIImage imageNamed:@"tab_home"] selectedImage:[UIImage imageNamed:@"tab_home_s"] title:@"首页"];
|
||||
|
||||
SPTrendContainerVC *dynamicVC = [[SPTrendContainerVC alloc] init];
|
||||
[self addPropertyToChildVC:dynamicVC image:[UIImage imageNamed:@"tab_dynamic"] selectedImage:[UIImage imageNamed:@"tab_dynamic_s"] title:@"动态"];
|
||||
|
||||
TXMessageVC *msgVC = [[TXMessageVC alloc] init];
|
||||
[self addPropertyToChildVC:msgVC image:[UIImage imageNamed:@"tab_msg"] selectedImage:[UIImage imageNamed:@"tab_msg_s"] title:@"消息"];
|
||||
|
||||
SPMineVC *mineVC = [[SPMineVC alloc] init];
|
||||
[self addPropertyToChildVC:mineVC image:[UIImage imageNamed:@"tab_mine"] selectedImage:[UIImage imageNamed:@"tab_mine_s"] title:@"我的"];
|
||||
}
|
||||
|
||||
- (void)onSweetParty {
|
||||
self.selectedIndex = 2;
|
||||
}
|
||||
|
||||
|
||||
- (void)addPropertyToChildVC:(UIViewController *)VC image:(UIImage *)image selectedImage:(UIImage *)selectedImage title:(NSString *)title {
|
||||
self.tabBar.translucent = NO;
|
||||
[[UITabBar appearance] setBarTintColor:kClearColor];
|
||||
[[UITabBar appearance] setTintColor:[UIColor clearColor]];
|
||||
[UITabBar appearance].translucent = NO;
|
||||
[UITabBar appearance].shadowImage = nil;
|
||||
|
||||
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
|
||||
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:11 weight:UIFontWeightMedium];
|
||||
attrs[NSForegroundColorAttributeName] = HEXCOLORA(0x999999, 1);
|
||||
|
||||
NSMutableDictionary *attrSelected = [NSMutableDictionary dictionary];
|
||||
attrSelected[NSFontAttributeName] = [UIFont systemFontOfSize:11 weight:UIFontWeightMedium];
|
||||
attrSelected[NSForegroundColorAttributeName] = HEXCOLOR(0x333333);
|
||||
|
||||
UITabBarItem *item = [UITabBarItem appearance];
|
||||
[item setTitleTextAttributes:attrs forState:UIControlStateNormal];
|
||||
[item setTitleTextAttributes:attrSelected forState:UIControlStateSelected];
|
||||
VC.title = title;
|
||||
VC.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||||
VC.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
||||
MainNavigationController *NAV = [[MainNavigationController alloc] initWithRootViewController:VC];
|
||||
[self addChildViewController:NAV];
|
||||
|
||||
if (@available(iOS 15.0, *)) {
|
||||
UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
|
||||
//tabBaritem title未选中状态颜色
|
||||
appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{NSForegroundColorAttributeName:HEXCOLORA(0x999999, 1)};
|
||||
//tabBaritem title选中状态颜色
|
||||
appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{NSForegroundColorAttributeName:HEXCOLOR(0x333333)};
|
||||
//tabBar背景颜色
|
||||
appearance.backgroundColor = kClearColor;
|
||||
// appearance.backgroundImage = ImageNamed(@"tabbar_backIMG");
|
||||
// appearance.backgroundImageContentMode = UIViewContentModeScaleToFill;
|
||||
// self.tabBar.scrollEdgeAppearance = appearance;
|
||||
// self.tabBar.standardAppearance = appearance;
|
||||
}else{
|
||||
self.tabBar.backgroundColor = UIColor.clearColor;
|
||||
// [self.tabBar setBackgroundImage:[ImageNamed(@"tabbar_backIMG") imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user