2.UITabBar Navigation
2015-05-30 09:45
507 查看
//
// AppDelegate.h
// Tab bar controllre
//
// Created by 红珊瑚 on 15/5/21.
// Copyright (c) 2015年
红珊瑚. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate :
UIResponder <UIApplicationDelegate>
{
}
@property (strong,
nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// Tab bar controllre
//
// Created by 红珊瑚 on 15/5/21.
// Copyright (c) 2015年
红珊瑚. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
#import "ViewController2.h"
#import "ViewController3.h"
#import "ViewController4.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
//创建Window
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
self.window.backgroundColor = [UIColor
whiteColor];
//1.创建并初始化tabBar控制器
UITabBarController *tabBarView = [[UITabBarController
alloc]
init];
//设置控制器为Window的根控制器
self.window.rootViewController = tabBarView;
//2.初始化4个子视图控制器
ViewController *ViewCon1 = [[ViewController
alloc]
init];
ViewController2 *ViewCon2 = [[ViewController2
alloc]
init];
ViewController3 *ViewCon3 = [[ViewController3
alloc]
init];
ViewController4 *ViewCon4 = [[ViewController4
alloc]
init];
//3.用导航试图控制器
管理4个子视图控制器
UINavigationController *NavigaCon1 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon1];
UINavigationController *NavigaCon2 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon2];
UINavigationController *NavigaCon3 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon3];
UINavigationController *NavigaCon4 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon4];
//为每一个导航控制器的title属性设置标题
NavigaCon1.title =
@"首页";
NavigaCon2.title =
@"名人";
NavigaCon3.title =
@"名车";
NavigaCon4.title =
@"我的";
//为每一个导航控制器的tabBarItem.image属性设置图标
NavigaCon1.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
NavigaCon2.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
NavigaCon3.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
NavigaCon4.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
//4.改变UITabBarItem的字的位置
[[UITabBarItem
appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -3.0)];
//5.创建一个数据包含4个导航控制器
NSArray *Controllers = [NSArray
arrayWithObjects:NavigaCon1,NavigaCon2,NavigaCon3,NavigaCon4,
nil];
//将数据传给UITabBarViewController
tabBarView.viewControllers = Controllers;
//设置Window为主窗口并显示出来
[self.window
makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application
and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
97e5
// AppDelegate.h
// Tab bar controllre
//
// Created by 红珊瑚 on 15/5/21.
// Copyright (c) 2015年
红珊瑚. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate :
UIResponder <UIApplicationDelegate>
{
}
@property (strong,
nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// Tab bar controllre
//
// Created by 红珊瑚 on 15/5/21.
// Copyright (c) 2015年
红珊瑚. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
#import "ViewController2.h"
#import "ViewController3.h"
#import "ViewController4.h"
@interface
AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
//创建Window
self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];
self.window.backgroundColor = [UIColor
whiteColor];
//1.创建并初始化tabBar控制器
UITabBarController *tabBarView = [[UITabBarController
alloc]
init];
//设置控制器为Window的根控制器
self.window.rootViewController = tabBarView;
//2.初始化4个子视图控制器
ViewController *ViewCon1 = [[ViewController
alloc]
init];
ViewController2 *ViewCon2 = [[ViewController2
alloc]
init];
ViewController3 *ViewCon3 = [[ViewController3
alloc]
init];
ViewController4 *ViewCon4 = [[ViewController4
alloc]
init];
//3.用导航试图控制器
管理4个子视图控制器
UINavigationController *NavigaCon1 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon1];
UINavigationController *NavigaCon2 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon2];
UINavigationController *NavigaCon3 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon3];
UINavigationController *NavigaCon4 = [[UINavigationController
alloc]
initWithRootViewController:ViewCon4];
//为每一个导航控制器的title属性设置标题
NavigaCon1.title =
@"首页";
NavigaCon2.title =
@"名人";
NavigaCon3.title =
@"名车";
NavigaCon4.title =
@"我的";
//为每一个导航控制器的tabBarItem.image属性设置图标
NavigaCon1.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
NavigaCon2.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
NavigaCon3.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
NavigaCon4.tabBarItem.image = [UIImage
imageNamed:@"check.png"];
//4.改变UITabBarItem的字的位置
[[UITabBarItem
appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -3.0)];
//5.创建一个数据包含4个导航控制器
NSArray *Controllers = [NSArray
arrayWithObjects:NavigaCon1,NavigaCon2,NavigaCon3,NavigaCon4,
nil];
//将数据传给UITabBarViewController
tabBarView.viewControllers = Controllers;
//设置Window为主窗口并显示出来
[self.window
makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application
and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
97e5
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- iOS开发之路--微博OAuth授权_取得用户授权的accessToken
- ios通过按钮点击异步加载图片
- ios中图像进行压缩方法汇总
- IOS检测指定路径的文件是否存在
- iOS、Mac OS X系统中编程实现汉字转拼音的方法(超级简单)