首次提交

This commit is contained in:
启星
2025-08-08 11:05:33 +08:00
parent 1b3bb91b4a
commit adc1a2a25d
8803 changed files with 708874 additions and 0 deletions

View 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];
// //NOviewtabbarYES
self.coustomBar.translucent = NO;
// //KVC tabbartabBar
[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