UINavigationController 导航控制器 IOS7适配 导航栏不透明


223115_Txo6_1451688.png

导航控制器使用了导航堆栈。根视图控制器(Settings)在堆栈最底层,以此类推。可以理解为一本书,一页一页的。这样就控制了 试图控制器

self.title = @"Settings"; // 改变标题
//其实这是一个区域 self.navigationItem.titleView = 
这是一个View 那就好办了,我们可以添加button imageView UISegmentedControl选项卡


    //视图控制器
ViewController1* vc = [[ViewController1 alloc] init];
    //导航控制器
    UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nc;

ViewController2* vc2 = [[ViewController2 alloc] init];
//进入第二个页面
[self.navigationController pushViewController:vc2 animated:YES];
//返回上一个页面
[self.navigationController popViewControllerAnimated:YES];
//返回根页面
    [self.navigationController popToRootViewControllerAnimated:YES];
//返回指定页面
  [self.navigationController popToViewController:vcX animated:YES];



223131_UDOi_1451688.jpg


bar:

包含左右UIBarButtonItem,也就是左右两个按钮,下面添加左面按钮:

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(clickLeftButton)];
//初始化并不是initWithBarButt....一种,聪明的你肯定知道comand点进去了。有initWithTitle。。。等等,这个可以改变按钮文字
    self.navigationItem.leftBarButtonItem = leftButton;

当然左边的默认显示的。右面的就不在这里添加了吧

下面是按钮样式,自行参考

225553_KoJQ_1451688.png


toolBar:

//显示toolBar
[self.navigationController setToolbarHidden:NO];
//添加toolBar 把UIBarButtonItem 放到,,,,,///UIBarButtonSystemItemFlexibleSpace 空白按钮风格
[self setToolbarItems:[NSArray arrayWithObjects:,,,, nil];


///自己添加UIToolbar
初始化 用setItems 添加 UIBarButtonItem
    UIToolbar* toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 416-84, 320, 44)];
    toolBar.hidden = YES;
    //toolBar.backgroundColor = [UIColor redColor];
    [self.view addSubview:toolBar];
    //批量给Toolbar添加按钮
    NSMutableArray* array = [NSMutableArray array];
    for (int i = 0; i < 7; i++) {
        if (i%2==0) {
            UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"%d",i] style:UIBarButtonItemStyleBordered target:self action:nil] autorelease];
            [array addObject:button];
        } else {
            UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];
            //宽
            //FixedSpace        固定空白
            //FlexibleSpace     灵活分布空白
            //button.width = 50;
            [array addObject:button];
        }
    }
    //如果是我们自己写的toolBar,用这个方法添加
    [toolBar setItems:array animated:YES];
    //如果是导航自带的toolBar,用这个方法添加
    [self setToolbarItems:array];

自定义按钮

//把自定义的按钮mybutton 添加到 UIBarButtonItem
barButton = [[UIBarButtonItem alloc] initWithCustomView:mybutton];

    // 让iOS7 导航控制器不透明

    self.navigationController.navigationBar.translucent = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;


//隐藏导航栏

[[self navigationController] setNavigationBarHidden:YES animated:YES];





转载于:https://my.oschina.net/liuchuanfeng/blog/201340

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值