iOS:导航栏的工具条和导航条

//
//  main.m
//  Hello
//
//  Created by lishujun on 14-8-28.
//  Copyright (c) 2014年 lishujun. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TestViewController : UIViewController
@end

@implementation TestViewController
-(void) loadView
{
    NSLog(@"load View");
    //创建视图对象
    UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor lightGrayColor];
    self.view = contentView;
}
@end

// --------------视图控制器对象--------------
@interface HelloWorldViewController : UIViewController
{
    UIToolbar *toolBar;
}
@end

@implementation HelloWorldViewController

-(void) loadView
{
    NSLog(@"load View");
    //创建视图对象
    UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor lightGrayColor];
    self.view = contentView;

    //设置工具栏并显示
    [self setNavBarAndShow];
    [self setUserToolBarAndShow];
}

//-----------设置导航栏并显示-----------------
-(void) setNavBarAndShow
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self action:@selector(pushView:)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Prev" style:UIBarButtonItemStylePlain target:self action:@selector(popView:)];
    [self.navigationController setNavigationBarHidden:NO]; // 显示之前隐藏的导航栏
}

-(void) pushView:(id)sender
{
    NSLog(@"push view");
    [self.navigationController pushViewController:[[TestViewController alloc]init] animated:YES];
}

-(void) popView:(id)sender
{
    NSLog(@"pop view");
    [self.navigationController popViewControllerAnimated:YES];
}

//------------设置工具栏并显示--------------
-(void) setNavToolBarAndShow
{
    // 设置NavigationController上的工具栏并显示
    UIBarButtonItem *one = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
    UIBarButtonItem *two = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];
    UIBarButtonItem *three = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
    UIBarButtonItem *four = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:nil action:nil];
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    [self setToolbarItems:[NSArray arrayWithObjects:flexItem, one, flexItem, two, flexItem, three, flexItem, four, flexItem, nil]];

    [self.navigationController setToolbarHidden:NO animated:NO];
}

-(void) setUserToolBarAndShow
{
    //设置自定义的toolbal
    [self.navigationController  setToolbarHidden:YES animated:YES];

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:nil action:nil];
    toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height - toolBar.frame.size.height - 44.0, self.view.frame.size.width, 44.0)];
    [toolBar setBarStyle:UIBarStyleDefault];
    toolBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    [toolBar setItems:[NSArray arrayWithObject:addButton]];
    [self.view addSubview:toolBar];
}

@end

// ----------------委托对象--------------------
@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
{
    IBOutlet UIWindow *window;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *nav;

@end

@implementation HelloWorldAppDelegate

@synthesize window;
@synthesize nav;

-(void) applicationDidFinishLaunching:(UIApplication *)application
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init];

    self.nav = [[UINavigationController alloc]initWithRootViewController: viewController];
    [self.nav setNavigationBarHidden:YES];        //隐藏导航栏,位于视图顶部
    [self.nav setToolbarHidden:YES];              //隐藏工具栏,位于视图底部

    self.window.rootViewController = self.nav;
    [self.window makeKeyAndVisible];
}
@end

// ---------------程序入口---------------------
int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
    }
}
时间: 2024-08-04 21:42:25

iOS:导航栏的工具条和导航条的相关文章

iOS开发 OC 导航栏 UINavigationController 工具条 UIToolBar

导航栏最常见的例子就是返回按钮的所在 在AppDelegate.m中,代码布局最开始定义窗口的时候, _window.rootViewController就应该为一个UINavigationController 这里的UINavigationController,戳进定义发现它是UIViewcontroller的子类 而之前代码布局中这里用的rootController是UIViewcontroller 所以它之中也是像之前代码布局中的UIViewcontroller一样是包含多个control

ios 导航栏透明, 上下滑动 导航栏 颜色渐变

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "PingFang SC"; color: #008400 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #3d1d81 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p4 {

iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)

                  #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end #import "AppDelegate.h" #import "KeyViewController.h" @interface Ap

iOS 顶部高斯模糊导航栏 + 页面内容穿越底部导航栏效果

(1)如果是使用系统导航栏则设置其translucent属性即可: [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new]; self.navigationController.navigationB

让导航栏变透明,去掉导航栏下面的线

下面代码可以让导航栏变透明 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsCompact];或者可以照一张透明的图片来填充也可以 隐藏导航栏下面的那根线navigationBar.shadowImage 这个方法不知为啥没用了 现在可以用下面这个代码这个代码是让下面那条线消失NSArray *list = self.navigationBar.

jquery导航栏html页面跳转导航字体变色

html代码: <div class="collapse"> <ul class="nav"> <li><a href="index.html" class="active">首页</a></li> <li> <a href="team.html"> 商务合作</a></li> <l

【转】【iOS】导航栏那些事儿

原文网址:http://www.jianshu.com/p/f797793d683f 参考文章 navigationItem UINavigationItem UINavigationBar UIBarButtonItem UIButton iOS 7 教程:定制iOS 7中的导航栏和状态栏 前言 本文试图阐释清楚导航栏相关的概念和用法,比如UINavigationBar和UINavigationItem的区别和联系,UIBarButtonItem的用法以及在纯代码和storyboard中有什么

iOS 7 教程:定制iOS 7中的导航栏和状态栏

目录(?)[-] iOS 7中默认的导航栏 设置导航栏的背景颜色 在导航栏中使用背景图片 定制返回按钮的颜 修改导航栏标题的字体 修改导航栏标题为图片 添加多个按钮 修改状态栏的风格 隐藏状态栏 总结 注:本文译自Customizing Navigation Bar and Status Bar in iOS 7 近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这

iOS 超 Easy 实现 渐变导航栏

接着上周的项目, 在上周我别出心裁的在自定义TabbarController中加入了自定义转场动画, 受到了大家广泛的喜爱, 再次表示感激, 今天我们继续实现LifestyleViewController的第二个功能渐变导航栏!! 渐变导航栏, 现在很多项目里都有这个功能, 我们就把这个功能集成到我们的项目中来; 根据设计图纸需求, 我们需要在轮播图下面有一个搜索栏, 搜索栏根据滑动偏移到导航栏之上. 具体怎么实现呢, Easy啦~ 不急,我们一步一步来. 创建搜索栏Cell 首先打开我们的项目