IOS15最标准的纯代码搭建项目
环境
ios 15
xCode13
Xnip2021-12-06_09-28-46.jpg
Xnip2021-12-06_09-33-51.jpg
如今手机更新速度快。屏幕大小不一,要求代码能力也越来越高。
既要适配iphone12,13以上产品,还要兼顾iphone8等产品。
storyBoard今天不提,可以做到二者都兼容。
创建项目,把Main有关的都删掉,info.plist都删掉,
在SceneDelegate.m里面书写。
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.rootViewController = [[LaunchViewController alloc]init];
[self.window makeKeyAndVisible];
}
创建一个控制器,继承于: UITabBarController,命名 LJMainTabBarController
在viewDidLoad调用如下函数。
- (void)addVCs {
NSArray* navNameArray = @[@"LJNewsViewController",
@"LJReaderViewController",
@"LJMediaViewController",
@"LJFoundViewController",
@"LJMeViewController"];
NSMutableArray* navArray = [[NSMutableArray alloc] init];
NSArray* titleArray = @[@"新闻",@"阅读",@"视听",@"发现",@"我"];
NSArray* imageArray = @[@"news",@"reader",@"media",@"found",@"me"];
for ( int i = 0; i < 5; i++) {
//添加视图控制器
UIViewController* vc = [[NSClassFromString(navNameArray[i]) alloc] init];
LJNavigationController* nav = [[LJNavigationController alloc] initWithRootViewController:vc];
[navArray addObject:nav];
//设置tabbarItem
NSString* imgNormalName = [NSString stringWithFormat:@"tabbar_icon_%@_normal",imageArray[i]];
NSString* imgHighlightName = [NSString stringWithFormat:@"tabbar_icon_%@_highlight",imageArray[i]];
UITabBarItem* tabBarItem = [[UITabBarItem alloc] initWithTitle:titleArray[i] image:[UIImage imageNamed:imgNormalName] tag:i+100];
tabBarItem.selectedImage = [UIImage imageNamed:imgHighlightName];
nav.tabBarItem = tabBarItem;
}
self.viewControllers = navArray;
self.tabBar.tintColor = kNetEaseRedColor;
}
网友评论