iOS:导航栏的工具条和导航条
功能:用NAV视图控制器打开新的视图,默认工具条和导航条隐藏,双击显示之
//
// 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");
}
}
iOS:导航栏的工具条和导航条的更多相关文章
- 通过HTML+CSS+JavaScript实现鼠标移动到页面顶部导航栏出现,如果移出导航栏3秒又隐藏起来,而且不受滚动条影响(二)
通过HTML+CSS+JavaScript实现鼠标移动到页面顶部导航栏出现,如果移出导航栏3秒又隐藏起来,而且不受滚动条影响(二) 效果:默认一直隐藏导航栏,当滚动条滚到超过300px按钮出现,点击回 ...
- iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...
- Flutter沉浸式状态栏/AppBar导航栏/仿咸鱼底部凸起导航
Flutter中如何实现沉浸式透明Statusbar状态栏效果? 如下图:状态栏是指android手机顶部显示手机状态信息的位置.android 自4.4开始新加入透明状态栏功能,状态栏可以自定义颜色 ...
- jquery导航栏html页面跳转导航字体变色
html代码: <div class="collapse"> <ul class="nav"> <li><a href ...
- zhuang 定制iOS 7中的导航栏和状态栏
近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这也就意味着导航栏 ...
- iOS 7 教程:定制iOS 7中的导航栏和状态栏
目录(?)[-] iOS 7中默认的导航栏 设置导航栏的背景颜色 在导航栏中使用背景图片 定制返回按钮的颜 修改导航栏标题的字体 修改导航栏标题为图片 添加多个按钮 修改状态栏的风格 隐藏状态栏 总结 ...
- iOS 超 Easy 实现 渐变导航栏
接着上周的项目, 在上周我别出心裁的在自定义TabbarController中加入了自定义转场动画, 受到了大家广泛的喜爱, 再次表示感激, 今天我们继续实现LifestyleViewControll ...
- (转)定制iOS 7中的导航栏和状态栏
近期,跟大多数开发者一样,我也正忙于对程序进行升级以适配iOS 7.最新的iOS 7外观上有大量的改动.从开发者的角度来看,导航栏和状态栏就发生了明显的变化.状态栏现在是半透明的了,这也就意味着导航栏 ...
- [iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)
A.导航栏两侧文字按钮 1.需求: 所有导航栏两侧的文字式按钮统一样式 普通样式:橙色 高亮样式:红色 不可用样式:亮灰 阴影:不使用 字体大小:15 github: https://github ...
随机推荐
- PHP超级全局变量总结
silicon1985 的 重要的PHP超级全局变量总结 PHP有9个提前定义变量数组.分别总结例如以下: 1.$_SERVER $_SERVER超级全局变量包括由webserver创建的信息.它提供 ...
- Nginx平台构架 分类: Nginx 2015-07-13 10:55 205人阅读 评论(0) 收藏
深入理解Nginx模块发开与架构解析读书笔记. nginx在启动后,在unix系统中会以daemon的方式(可以手动关闭 nginx.conf daemon off)在后台运行,后台进程包含一个mas ...
- java -Xmx3550m -Xms3550m -Xmn2g -Xss128k
java -Xmx3550m -Xms3550m -Xmn2g -Xss128k1.-Xmx3550m:设置JVM最大可用内存为3550M.2.-Xms3550m:设置JVM促使内存为3550m.此值 ...
- j2ee学习笔记URLEncoder.encode(String , enc)处理特殊字符
从页面上传递数据时,特殊字符对于超链接会自动进行解码 : 其他方式需要手动进行解码.
- Java 反射学习笔记
要学反射,先要了解Class这个类,Class是所有Java类的一个总称,Class的实例中存储的是一个类的字节码,获取Class的实例有三种方式: System.class new Date().g ...
- Android Studio: 我解决的DEX出错。
今天开始使用了Android Studio.感觉很方便,很强大.因为它还集成了SVN,GIT等版本管理工具. 由于工程在CheckOut下来后想直接在终端上运行,在引入外部jar包之后开始运行啦,结果 ...
- CentOS 6.7安装配置Ansible
1.准备CentOS环境 yum update && yum upgrade 2.控制服务器与被管理服务器要求 Master:Python 2.6+ Slave:Python 2.4+ ...
- json 是什么
怎么学习一个知识? 首先要提出几个问题,目前认为json是个什么,json是谁创造的,为什么而出现的,但是目前仅有很长时间之前别人直接告诉我的,json用来存数据的,对于使用也忘记的差不多了,所以现在 ...
- JVM垃圾回收理论知识
- python基础知识一
数 python中有4种类型的数--整数.长整数.浮点数和复数. --2是一个整数 --长整数不过是大一些的整数 --3.23和52.3E-4是浮点数的例子.E标记表示10的幂.在这里52.3E-4表 ...