UITabBarController 微信

时间:2023-03-09 19:37:02
UITabBarController 微信

AppDelegate.m

 #import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. // 第一步:创建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; // 第二步:创建UITabBarController对象
UITabBarController *mainTab = [[UITabBarController alloc] init];
//mainTab.tabBar.barTintColor = [UIColor purpleColor];
mainTab.tabBar.tintColor = [UIColor colorWithRed: / 255.0 green: / 255.0 blue: alpha:]; // 第三步:设置window的根控制器
self.window.rootViewController = mainTab; // 第四步:设置UITabBarController的控制器数组
// 4.1 创建导航控制器并制定导航控制器的根视图
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:[[FirstViewController alloc] init]]; UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:[[SecondViewController alloc] init]]; UINavigationController *thirdNav = [[UINavigationController alloc] initWithRootViewController:[[ThirdViewController alloc] init]]; UINavigationController *fourthNav = [[UINavigationController alloc] initWithRootViewController:[[FourthViewController alloc] init]]; // 4.2 设置导航控制器的TabBarItem
UIImage *img1 = [UIImage imageNamed:@"tabbar_mainframe@3x"];
UIImage *imgS1 = [[UIImage imageNamed:@"tabbar_mainframeHL@3x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // 设置选中的图片保留图片原有的样式,不进行渲染 UIImage *img2 = [UIImage imageNamed:@"tabbar_contacts@3x"];
UIImage *imgS2 = [[UIImage imageNamed:@"tabbar_contactsHL@3x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *img3 = [UIImage imageNamed:@"tabbar_discover@3x"];
UIImage *imgS3 = [[UIImage imageNamed:@"tabbar_discoverHL@3x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *img4 = [UIImage imageNamed:@"tabbar_me@3x"];
UIImage *imgS4 = [[UIImage imageNamed:@"tabbar_meHL@3x"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; firstNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"微信" image:img1 selectedImage:imgS1];
secondNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通讯录" image:img2 selectedImage:imgS2];
thirdNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:img3 selectedImage:imgS3];
fourthNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:img4 selectedImage:imgS4]; // 4.3 将导航控制器对象添加到数组中
//[mainTab addChildViewController:firstNav];
mainTab.viewControllers = @[firstNav, secondNav, thirdNav, fourthNav]; #pragma mark - UIAppearance // 一键设置
[UINavigationBar appearance].barTintColor = [UIColor blackColor]; [UINavigationBar appearance].barStyle = UIBarStyleBlack; [UINavigationBar appearance].tintColor = [UIColor whiteColor]; // 同理,也有,但是只有一个tabbar,没必要而已
// [UITabBar appearance] return YES;
} @end

FirstViewController.m

 #import "FirstViewController.h"
#import "Test1ViewController.h" @interface FirstViewController () @end @implementation FirstViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. self.title = @"微信";
self.navigationController.navigationBar.barTintColor = [UIColor blackColor]; // [self.navigationController.navigationBar setBackgroundImage:<#(nullable UIImage *)#> forBarMetrics:<#(UIBarMetrics)#>] // 修改title的颜色和大小
// [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : [UIFont systemFontOfSize:20]}]; // 设置barstyle修改状态栏(简单,可以用)
// self.navigationController.navigationBar.barStyle = UIBarStyleBlack; // 添加右按钮
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(click:)]; } - (void)click:(UIBarButtonItem *)sender { Test1ViewController *test1VC = [[Test1ViewController alloc] init]; // 设置push隐藏tabbar
test1VC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:test1VC animated:YES];
} @end