日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS15最标准的纯代码搭建项目

發布時間:2023/12/18 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS15最标准的纯代码搭建项目 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IOS15最標準的純代碼搭建項目

環境

xCode 13 ios 15


如今手機產品更新日新月異。ios既要適配iPhone12,13這樣的劉海機型,還要適配iphone8-5s這樣的老機型。如何使用純代碼創建一套兩者都適用的。
今天不提StoryBoard,StoryBoard試過,沒有問題。
首先創建一個項目,把Main有關的全部刪掉,例如 Main.storyboard, info.plist里面的Main,選中項目,下面的Main。ViewController.h和.m文件。
來到 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 = [[LJMainTabBarController alloc]init];[self.window makeKeyAndVisible]; }

2. 新建一個 LJMainTabBarController 繼承UITabBarController

在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];//設置tabbarItemNSString* 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; }

當然也需要一個LJNavigationController 來包裝每一個控制器。
繼承于 基類 UINavigationController
在里面重寫方法:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{if(self.childViewControllers.count>0){viewController.hidesBottomBarWhenPushed = YES;}[super pushViewController:viewController animated:animated]; }

測試在iphone13和ipod 均可正常顯示。于StoryBoard創建出來的并無區別。

總結

以上是生活随笔為你收集整理的IOS15最标准的纯代码搭建项目的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。