iOS 导航条(navigation)
2013-10-16 13:45
477 查看
1.初始化
-
(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]]
autorelease];
self.viewController = [[[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil]
autorelease];
UINavigationController *nav =
[[[UINavigationController alloc]
initWithRootViewController:self.viewController]
autorelease];
nav.navigationBar.barStyle =
UIBarStyleBlack;
self.window.rootViewController =
nav;
[self.window makeKeyAndVisible];
return YES;
}
UIBarButtonItem *barButtonItem =
[[UIBarButtonItem alloc] init];
barButtonItem.title =
@"buttonName";
self.navigationItem.backBarButtonItem =
barButtonItem;
[barButtonItem release]
//返回到上一个视图,比如用户单击导航栏的Back按钮
[[self navigationController]
popViewControllerAnimated:YES]
//返回到根视图
[[self navigationController]
popToRootViewControllerAnimated:YES];
//返回到任意视图
[[self navigationController]
popToViewController:destiationViewController
animated:YES];
该代码添加一个自定义的UILabel,但也可以添加其他任意控件(或者视图),比如UIImageView,UISwitch等等。
self.navigationItem.titleView = [[[UILabel
alloc]
initWithFrame:CGRectMake(0.0f,0.0f, 120.0f,
36.0f)] autorelease];
self.title = @"Hello";
self.navigationItem.rightBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:@"Action"
style:UIBarButtonItemStylePlain target:self
action:@selector(performAction:)] autorelease];
-
(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]]
autorelease];
self.viewController = [[[ViewController alloc]
initWithNibName:@"ViewController" bundle:nil]
autorelease];
UINavigationController *nav =
[[[UINavigationController alloc]
initWithRootViewController:self.viewController]
autorelease];
nav.navigationBar.barStyle =
UIBarStyleBlack;
self.window.rootViewController =
nav;
[self.window makeKeyAndVisible];
return YES;
}
2.更改导航条上返回按钮的标题
UIBarButtonItem *barButtonItem =[[UIBarButtonItem alloc] init];
barButtonItem.title =
@"buttonName";
self.navigationItem.backBarButtonItem =
barButtonItem;
[barButtonItem release]
3.返回到上一个视图,返回根视图以及返回到任意视图
//返回到上一个视图,比如用户单击导航栏的Back按钮[[self navigationController]
popViewControllerAnimated:YES]
//返回到根视图
[[self navigationController]
popToRootViewControllerAnimated:YES];
//返回到任意视图
[[self navigationController]
popToViewController:destiationViewController
animated:YES];
4.添加自定义视图到导航条的标题栏
该代码添加一个自定义的UILabel,但也可以添加其他任意控件(或者视图),比如UIImageView,UISwitch等等。self.navigationItem.titleView = [[[UILabel
alloc]
initWithFrame:CGRectMake(0.0f,0.0f, 120.0f,
36.0f)] autorelease];
self.title = @"Hello";
5.为导航添加新按钮
修改navigationItem可以为导航栏添加新按钮,如果要删除按钮,将该项指定为空值即可。下面代码是为导航栏添加右边按钮
self.navigationItem.rightBarButtonItem =[[[UIBarButtonItem alloc] initWithTitle:@"Action"
style:UIBarButtonItemStylePlain target:self
action:@selector(performAction:)] autorelease];
相关文章推荐
- 4000 IOS开发 导航条…
- IOS 5 设置NavigationBar 背景
- iOS 更改导航条上返回按钮的标题
- iOS 在导航条上添加自定义的u…
- ios 修改textField的placehol…
- iOS cookie 的使用(相当重要)
- IOS Storyboard解析
- iOS APP设计规范大全
- iOS 动画总结—UIView动画
- <转> iOS开发网络篇—大文件的…
- IOS之UI  绘图(笔记)
- IOS 代理传值
- IOS init、loadView、viewDidLoad…
- 第三天 打开地图《苹果iOS实…
- iphone之navigationItem 添…
- IOS 关灯游戏
- ios点击链接直接跳转到 App&n…
- IOS开发之----strong和weak (…
- IOS APP 真机测试步骤
- IOS 7 Xcode 5 免IDP证书 真机调试