用IB实现标签导航不用写一个代码
1.用Tabbed Application模版新建一个工程;
2.添加View Controller
3.按住control键,从Tab Bar Controller Scene拖一个线到新建的View Controller,在跳出的选项框中选择view controllers
4.修改标签图文,要为不同的设备准备不同的图标:
普通显示屏——无后缀
Retina显示屏——@2x
iphone Plus Retina显示屏——@3x
5.界面布局
6.删各页面对应的类,然后再自己建,全部继承自UIViewController
代码实现
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//新建窗口并设置其大小
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
//使被使用对象的主窗口显示到屏幕的最前端
[self.window makeKeyAndVisible];
//新建UITabBarController类控制器,并设置其为根视图控制器
UITabBarController *tabBarController = [[UITabBarController alloc] init];
self.window.rootViewController = tabBarController;
UIViewController *viewController1 = [[HeiViewController alloc]initWithNibName:@"HeiViewController" bundle:nil];
UIViewController *viewController2 = [[JiViewController alloc]initWithNibName:@"JiViewController" bundle:nil];
UIViewController *viewController3 = [[LiaoViewController alloc]initWithNibName:@"LiaoViewController" bundle:nil];
tabBarController.viewControllers = @[viewController1,viewController2,viewController3];
return YES;
}
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"黑龙江";
self.tabBarItem.image = [UIImage imageNamed:@"Hei"];
}
}