UI_导航视图控制器

这里写图片描述

AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];

    1.先创建一个视图控制器对象.
    RootViewController *rootVC = [[RootViewController alloc] init];

    2.创建一个导航视图控制器.
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];

    3.指定导航视图控制器称为window的根视图控制器
    self.window.rootViewController = naVC;

    4.内存管理
    [rootVC release];
    [naVC release];

    return YES;
}
RootViewController.m
#import "RootViewController.h"
#import "SecondViewController.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];

    // 通过两方面设置naVC的样式.

    // 第一部分:外观.
    // 修改背景颜色,不是所有的颜色都是backgroundColor.   self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];

    // 设置成不透明
   self.navigationController.navigationBar.translucent = NO;
#warning 导航视图控制器里的navigationbar默认是半透明效果,但是不透明效果会修改坐标系的起点,如果想要半透明效果,为了让视图全部显示,需要把坐标向下平移64.

    UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    view.backgroundColor = [UIColor blueColor];
    [self.view addSubview:view];
    [view release];

    // 第二部分:内容.
    // 添加标题.
    self.title = @"标题";
    self.navigationItem.title = @"标题";
    // 设置中心位置添加一个视图.
    UISegmentedControl *segmentedC = [[UISegmentedControl alloc] initWithItems:@[@"通话", @"信息"]];
    self.navigationItem.titleView = segmentedC;

    // 创建左右两边两个按钮.
    // 采用了系统默认的按钮样式进行创建.
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(click:)] autorelease];
    // 把按钮内容设置成文字
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"测试" style:UIBarButtonItemStylePlain target:self action:@selector(click:)] autorelease];

    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    itemButton.frame = CGRectMake(0, 0, 40, 40);
    // 如果不适用自定义的视图,图片都是蓝色的,只有自定义的视图才能正常显示图片样式.
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:itemButton] autorelease];


    // 外观设置通过navigationBar来操作,能设置半透明和颜色(bartintcolor)
    // 内容通过navigationitem来操作,可以设置左右按钮,中间标题title,titleView

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 10;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(100, 100, 150, 50);
    [self.view addSubview:button];

}
- (void)buttonAction:(UIButton *)button {
    // 模态跳转
//    SecondViewController *secondVC = [[SecondViewController alloc] init];
//    [secondVC setModalTransitionStyle:UIModalTransitionStylePartialCurl];
//    [self presentViewController:secondVC animated:YES completion:^{
//        
//    }];
//    [secondVC release];

    // push下一个页面.
    // 先创建一个目标页面对象.
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:secondVC animated:YES];
    [secondVC release];

    NSLog(@"%@", self.navigationController);
}

- (void)click:(UIBarButtonItem *)item {
    NSLog(@"我被点击了");
}
SecondViewController.m

#import "SecondViewController.h"
#import "ThirdViewController.h"
@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"第二页";
    self.view.backgroundColor = [UIColor cyanColor];

    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    itemButton.frame = CGRectMake(0, 0, 40, 40);
    // 如果不适用自定义的视图,图片都是蓝色的,只有自定义的视图才能正常显示图片样式.
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:itemButton] autorelease];


    // 外观设置通过navigationBar来操作,能设置半透明和颜色(bartintcolor)
    // 内容通过navigationitem来操作,可以设置左右按钮,中间标题title,titleView

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 10;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(100, 100, 150, 50);
    [self.view addSubview:button];


}

- (void)buttonAction:(UIButton *)button {
    // 模态跳转
    //    SecondViewController *secondVC = [[SecondViewController alloc] init];
    //    [secondVC setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    //    [self presentViewController:secondVC animated:YES completion:^{
    //
    //    }];
    //    [secondVC release];

    // push下一个页面.
    // 先创建一个目标页面对象.
    ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
    [self.navigationController pushViewController:thirdVC animated:YES];
    [thirdVC release];

    NSLog(@"%@", self.navigationController);
}
ThirdViewController.m

#import "ThirdViewController.h"
#import "FourthViewController.h"
@interface ThirdViewController ()

@end

@implementation ThirdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"第三页";
    self.view.backgroundColor = [UIColor grayColor];

    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    itemButton.frame = CGRectMake(0, 0, 40, 40);
    // 如果不适用自定义的视图,图片都是蓝色的,只有自定义的视图才能正常显示图片样式.
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:itemButton] autorelease];


    // 外观设置通过navigationBar来操作,能设置半透明和颜色(bartintcolor)
    // 内容通过navigationitem来操作,可以设置左右按钮,中间标题title,titleView

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 10;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(100, 100, 150, 50);
    [self.view addSubview:button];


}

- (void)buttonAction:(UIButton *)button {
    // 模态跳转
    //    SecondViewController *secondVC = [[SecondViewController alloc] init];
    //    [secondVC setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    //    [self presentViewController:secondVC animated:YES completion:^{
    //
    //    }];
    //    [secondVC release];

    // push下一个页面.
    // 先创建一个目标页面对象.
    FourthViewController *fourthVC = [FourthViewController alloc];
    [self.navigationController pushViewController:fourthVC animated:YES];
    [fourthVC release];

    NSLog(@"%@", self.navigationController.viewControllers);
}
FourthViewController.m

#import "FourthViewController.h"
#import "FifthViewController.h"
@interface FourthViewController ()

@end

@implementation FourthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"第四页";
    self.view.backgroundColor = [UIColor yellowColor];

    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    itemButton.frame = CGRectMake(0, 0, 40, 40);
    // 如果不适用自定义的视图,图片都是蓝色的,只有自定义的视图才能正常显示图片样式.
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:itemButton] autorelease];


    // 外观设置通过navigationBar来操作,能设置半透明和颜色(bartintcolor)
    // 内容通过navigationitem来操作,可以设置左右按钮,中间标题title,titleView

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 10;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(100, 100, 150, 50);
    [self.view addSubview:button];


}

- (void)buttonAction:(UIButton *)button {
    // 模态跳转
    //    SecondViewController *secondVC = [[SecondViewController alloc] init];
    //    [secondVC setModalTransitionStyle:UIModalTransitionStylePartialCurl];
    //    [self presentViewController:secondVC animated:YES completion:^{
    //
    //    }];
    //    [secondVC release];

    // push下一个页面.
    // 先创建一个目标页面对象.
    FifthViewController *fifthVC = [[FifthViewController alloc] init];
    [self.navigationController pushViewController:fifthVC animated:YES];
    [fifthVC release];

    NSLog(@"%@", self.navigationController.viewControllers);
}
FifthViewController.m

#import "FifthViewController.h"
@interface FifthViewController ()

@end

@implementation FifthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"第五页";
    self.view.backgroundColor = [UIColor redColor];

    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
    itemButton.frame = CGRectMake(0, 0, 40, 40);
    // 如果不适用自定义的视图,图片都是蓝色的,只有自定义的视图才能正常显示图片样式.
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:itemButton] autorelease];


    // 外观设置通过navigationBar来操作,能设置半透明和颜色(bartintcolor)
    // 内容通过navigationitem来操作,可以设置左右按钮,中间标题title,titleView

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 10;
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(100, 100, 150, 50);
    [self.view addSubview:button];


}

- (void)buttonAction:(UIButton *)button {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值