2015-12-16 UI7_UINavigationController

2015-12-16 13:31:31

//
// RootViewController.m
// UI7_UINavigationController
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

  • (void)viewDidLoad {

    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    
    //********< 导航栏设置>************//
    //< 半透明效果 >****
    self.navigationController.navigationBar.translucent = YES;
    // 半透明下 坐标原点在屏幕左上角   默认半透明
    // 不透明下 坐标原点在导航栏左下角
    
    UIView *aview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    aview.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:aview];
    [aview release];
    //**< 显示/隐藏> ****
    self.navigationController.navigationBarHidden = NO;
    //**< 导航栏背景颜色>****
    self.navigationController.navigationBar.backgroundColor = [UIColor grayColor];
    //**< 导航栏颜色>****
    // 状态栏(statuBar)会跟随导航栏一起变色

    // self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];

    //**< 导航栏样式 >****两种方式

    // self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    
    //*****<导航标题>***

    // self.title = @"标题";

// self.navigationItem.title = @"标题";


//****< 导航标题视图 >****
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"电话", @"聊天"]];
seg.frame = CGRectMake(100, 100, 120, 30);
// 默认选中
seg.selectedSegmentIndex = 0;
// 添加到导航栏中间
self.navigationItem.titleView = seg;
[seg release];
//******< 导航栏按钮>****
// 左按钮

// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(left:)];

// 自定义 左按钮
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"2"]style:UIBarButtonItemStylePlain target:self action:@selector(left:)] autorelease];
// 右按钮
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"1"] style:UIBarButtonItemStylePlain target:self action:@selector(right:)]autorelease];

// self.navigationItem.rightBarButtonItems = [[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@""] style: target:self action:@selector(right:)] autorelease];


// 按钮对象
UIBarButtonItem *item1 =[[[UIBarButtonItem alloc]
  initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
  action:@selector(leftAction)] autorelease];
UIBarButtonItem *item2 =[[[UIBarButtonItem alloc]
  initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self
  action:@selector(leftAction)] autorelease];
// 左按钮数组
self.navigationItem.leftBarButtonItems = @[item1, item2];
// 右按钮数组
self.navigationItem.rightBarButtonItems= @[item1,item2];


///******<  item颜色>****
self.navigationController.navigationBar.tintColor = [UIColor blackColor];





}

  • (void)leftAction
    {

    }

    -(void)right:(UIBarButtonItem *)btn

{

NSLog(@"%@", btn);

}

  • (void)left:(UIBarButtonItem *)btn
    {

    NSLog(@"%@", btn);

    }

  • (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

    }

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.

    }

*/

@end

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »