标签:
在iOS平台上创建有个工程,之后在工程中创建两个类视图
操作步骤如下
1、在分别在两个类视图中对主视图设置背景色
FirstViewController.m
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
//设置主视图的背景色
self.view.backgroundColor=[UIColor greenColor];
}
SecondViewController.m
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
//设置主视图的背景色
self.view.backgroundColor=[UIColor blueColor];
}
2、在
AppDelegate中创建导航栏和根视图
AppDelegate.h
#import <UIKit/UIKit.h>
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//创建视图对象
FirstViewController *firstVC=[[FirstViewController alloc]init];
SecondViewController *secondVC=[[SecondViewController alloc]init];
//导航栏
UINavigationController *naviGC=[[UINavigationController alloc]initWithRootViewController:firstVC];
naviGC.tabBarItem.title=@"first";
naviGC.tabBarItem.badgeValue=@"4";
secondVC.tabBarItem.title=@"second";
secondVC.tabBarItem.badgeValue=@"1";
UITabBarController *tabBarC=[[UITabBarController alloc]init];
[tabBarC setViewControllers:@[naviGC,secondVC]];
//根视图
self.window.rootViewController=tabBarC;
return YES;
}
3、结果效果图
分别点击视图的中的“4(first)”和“1(second)”可以切换到对应的视图
iOS设计之 多视图导航栏UINavigationController切换视图的简单设计
标签:
原文地址:http://www.cnblogs.com/guiyangxueyuan/p/5277119.html