18、UINavigaionBar-OC+UI

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值