你真的会用storyboard开发吗?
生活随笔
收集整理的這篇文章主要介紹了
你真的会用storyboard开发吗?
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
在一般的布局中,我們先使用一個plist文件,做為tabbarVC的的4個選項 pilist文件如下 然后創(chuàng)建多個Storyboard,以及Storyboard關(guān)聯(lián)的文件, 然后刪除啟動的一些sb界面,讓界面啟動時候從AppDelegate中啟動, 在AppDelegate中寫下如下代碼
<!-- lang: cpp --> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch.self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; //b不要在主方法中寫碎代碼 [self setUI]; [self.window makeKeyAndVisible]; return YES;}
-(void)setUI{
UITabBarController *uiTabBar = [[UITabBarController alloc] init];NSURL *url = [[NSBundle mainBundle] URLForResource:@"MainUI" withExtension:@"plist"]; NSArray *arr = [NSArray arrayWithContentsOfURL:url];for (NSDictionary *dic in arr) {UIStoryboard *sb = [UIStoryboard storyboardWithName:dic[@"vcName"] bundle:nil];UIViewController *uiVC = sb.instantiateInitialViewController;uiVC.title = dic[@"title"];uiVC.tabBarItem.image = [UIImage imageNamed:dic[@"icon"]];uiVC.tabBarItem.badgeValue = dic[@"badgeNumber"];[uiTabBar addChildViewController:uiVC]; }self.window.rootViewController = uiTabBar;}
然后就能看到如下功能了,
效果如下
那在SB文件中的按鈕點擊跳轉(zhuǎn)到其他SB文件中怎么處理呢?如下代碼:
<!-- lang: cpp -->- (IBAction)clickBtn:(id)sender { UIStoryboard *sb = [UIStoryboard storyboardWithName:@"hhh" bundle:nil]; UIViewController *vc = sb.instantiateInitialViewController; [self.navigationController pushViewController:vc animated:YES]; }
當然我講的肯定不是很清晰,下面你看下我的源代碼吧!嘻嘻,希望對你有用!
下面是我在gitthub上詳細地址:https://github.com/pyawkk/SB-.git
轉(zhuǎn)載于:https://my.oschina.net/panyong/blog/372385
總結(jié)
以上是生活随笔為你收集整理的你真的会用storyboard开发吗?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: qsv格式转换mp4(视频格式转换器大全
- 下一篇: php是什么意思