#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//创建导航栏视图
UINavigationController *navc1=[[UINavigationController alloc] initWithRootViewController:[FirstViewController new]];
//分栏名字
navc1.tabBarItem.title=@"消息";
//提示消息
navc1.tabBarItem.badgeValue=@"2";
//添加图片
navc1.tabBarItem.image=[UIImage imageNamed:@"1"];
UINavigationController *navc2=[[UINavigationController alloc] initWithRootViewController:[SecondViewController new]];
navc2.title=@"动态";
navc2.tabBarItem.badgeValue=@"2";
//创建分栏
UITabBarController *tab=[[UITabBarController alloc] init];
//将两个导航栏添加到底部视图
tab.viewControllers=@[navc1,navc2];
navc2.tabBarItem.image=[UIImage imageNamed:@"2"];
//添加前景色
tab.tabBar.tintColor=[UIColor greenColor];
//将底部视图添加到根视图上
self.window.rootViewController=tab;
return YES;
}
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController
@end
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//更换背景色
self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"20141110_f64c52ed5be2176adaa1mADR4skv4nYU.jpg"]];
//添加标题
self.title=@"第一个视图";
//更换标题的前景色
self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor yellowColor]};
//创建一个导航栏按钮
UIBarButtonItem *Tab=[[UIBarButtonItem alloc] initWithTitle:@"next" style:2 target:self action:@selector(Next)];
//更改前景色
Tab.tintColor=[UIColor redColor];
//添加右边按钮
self.navigationItem.rightBarButtonItem=Tab;
}
-(void)Next
{
SecondViewController *second=[[SecondViewController alloc] init];
//导航栏视图 :推到下一页
[self.navigationController pushViewController:second animated:YES];
}
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"8efce6cd7b899e51feb2371b40a7d933c8950d83.jpg"]];
self.title=@"第二个视图";
self.navigationController.navigationBar.titleTextAttributes=@{NSForegroundColorAttributeName:[UIColor greenColor]};
UIBarButtonItem *tab=[[UIBarButtonItem alloc] initWithTitle:@"back" style:2 target:self action:@selector(BackPage)];
self.navigationItem.leftBarButtonItem=tab;
}
-(void)BackPage
{
//出栈 返回到上一页
[self.navigationController popViewControllerAnimated:YES];
}