UINavigaionBar :
//
// RootViewController.m
// NavigetionBarDemo
//
// Created by ccy on 13-12-29.
// Copyright (c) 2013年 ccy. All rights reserved.
//
#import "RootViewController.h"
#import "SecondViewController.h"
@interface RootViewController ()
{
SecondViewController * _secondVC;
}
@end
@implementation RootViewController
- (void)dealloc
{
[_secondVC release];
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor greenColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(10, 30, 300, 30);
[btn setTitle:@"second view" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
//默认 高44 宽320
//导航条风格
/*
UIBarStyleDefault = 0, - 默认颜色
UIBarStyleBlack = 1, - 黑色
UIBarStyleBlackOpaque = 1, - 黑色全透明
UIBarStyleBlackTranslucent = 2, - 黑色半透明
*/
//self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
//只有导航条风格设置为半透明,背景颜色才能生效
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
//设置导航条背景图片
/*
UIBarMetrics 设置 iphone 两种模式:
UIBarMetricsDefault, - 默认 树屏幕模式
UIBarMetricsLandscapePhone, - 横屏模式
注意:如果图片过大不会自动压缩。
*/
//[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"mingzi.png"] forBarMetrics:(UIBarMetrics)];
//裁减
//self.navigationController.navigationBar.clipsToBounds = YES;
//隐藏 这两个视图公用一个导航条,这个操作后,两个导航条都不见了
self.navigationController.navigationBarHidden = YES;
_secondVC = [[SecondViewController alloc] init];
}
- (void)btnclick
{
[self.navigationController pushViewController:_secondVC animated:YES];
}
//
// SecondViewController.m
// NavigetionBarDemo
//
// Created by ccy on 13-12-29.
// Copyright (c) 2013年 ccy. All rights reserved.
//
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
self.navigationController.navigationBarHidden = NO;
}
//
// ccyAppDelegate.m
// NavigetionBarDemo
//
// Created by ccy on 13-12-29.
// Copyright (c) 2013年 ccy. All rights reserved.
//
#import "ccyAppDelegate.h"
#import "RootViewController.h"
@implementation ccyAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
RootViewController * rootVC = [[RootViewController alloc] init];
UINavigationController * navigationC = [[UINavigationController alloc] initWithRootViewController:rootVC];
[rootVC release];
self.window.rootViewController = navigationC;
[navigationC release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}