//
// AppDelegate.h
// tabbar
//
// Created by iOS on 2022/7/29.
//
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic, strong) UIWindow * window;
@end
//
// AppDelegate.m
// UITabbarProject
//
// Created by apple on 2024/5/5.
//
#import "AppDelegate.h"
#import "ViewController.h"
#import "ViewController2.h"
#import "ViewController1.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
// 创建tabbar所管理的子控制器,每个子控制器都带有一个导航
ViewController1 *redVC = [[ViewController1 alloc] init];
UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:redVC];
ViewController2 *greenVC = [[ViewController2 alloc] init];
UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:greenVC];
// 创建UITabBarController对象
UITabBarController *tabbar = [[UITabBarController alloc] init];
// 设置tabbar的子控制器
tabbar.viewControllers = @[navi1, navi2];
tabbar.view.backgroundColor = [UIColor whiteColor];
// 将标签控制器设置为根视图控制器
self.window.rootViewController = tabbar;
[self.window makeKeyAndVisible];
UITabBar *tab = tabbar.tabBar;
tab.backgroundColor = [UIColor whiteColor];
UITabBarItem *item = tab.items[0];
item.image = [self resizeImage:[UIImage imageNamed:@"home.png"] newSize:CGSizeMake(30, 30)];
item.title = @"首页";
UITabBarItem *item2 = tab.items[1];
item2.image = [self resizeImage:[UIImage imageNamed:@"user.png"] newSize:CGSizeMake(30, 30)];
item2.title = @"发现";
item2.badgeValue = @"900";
return YES;
}
- (UIImage *)resizeImage:(UIImage *)image newSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
//
// ViewController.h
// tabbar
//
// Created by iOS on 2022/7/29.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
//
// ViewController.m
// tabbar
//
// Created by iOS on 2022/7/29.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
@end
//
// ViewController2.h
// UITabbarProject
//
// Created by apple on 2024/5/5.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ViewController2 : UIViewController
@end
NS_ASSUME_NONNULL_END
//
// ViewController2.m
// UITabbarProject
//
// Created by apple on 2024/5/5.
//
#import "ViewController2.h"
#import "ViewController.h"
@interface ViewController2 ()
@end
@implementation ViewController2
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor systemBlueColor],NSFontAttributeName:[UIFont systemFontOfSize:18.0f]}];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(Nextpage)];
self.navigationItem.title = @"红色";
// UIView *white =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 500, 64)];
// white.backgroundColor = [UIColor whiteColor];
// [self.view addSubview:white];
}
-(void)Nextpage
{
ViewController *blue = [[ViewController alloc]init];
blue.hidesBottomBarWhenPushed = YES; // 隐藏底部导航栏
[self.navigationController pushViewController:blue animated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// ViewController1.h
// UITabbarProject
//
// Created by apple on 2024/5/5.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ViewController1 : UIViewController
@end
NS_ASSUME_NONNULL_END
//
// ViewController1.m
// UITabbarProject
//
// Created by apple on 2024/5/5.
//
#import "ViewController1.h"
@interface ViewController1 ()
@end
@implementation ViewController1
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
self.navigationItem.title = @"绿色";
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
视频审核太慢了就不贴了