UINavigationController, UITabBarController
来源:互联网 发布:佳能调焦软件 编辑:程序博客网 时间:2024/05/05 17:47
UITabBarController
通用
AppDelegate.m
self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; [_window release]; ViewController *vc = [[ViewController alloc] init]; UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:vc]; // 创建 TabBar 按钮的样式 naVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1000]; SecondViewController *secVC = [[SecondViewController alloc] init]; UINavigationController *secNAVC = [[UINavigationController alloc] initWithRootViewController:secVC]; secNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"shop" image:[UIImage imageNamed:@"1.png"] selectedImage:[UIImage imageNamed:@"2.png"]]; // 创建 tabBarController UITabBarController *tab = [[UITabBarController alloc] init]; tab.viewControllers = @[naVC, secNAVC, ...]; // 给 window 设置根视图控制器 self.window.rootViewController = tab; // 编程的时候, 设置默认的出现页面,不用每次都从第0个开始 tab.selectedIndex = 3; tab.delegate = self; [tab release]; [naVC release]; [vc release];
property
naVC.tabBarItem.badgeValue
小红点的内容, 无小红点时为 nil naVC.tabBarItem
创建 tabBar 按钮的样式
eg.
naVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1000];或者naVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"shop" image:[UIImage imageNamed:@"1.png"] selectedImage:[UIImage imageNamed:@"2.png"]];
UITabBarController的外观设置 tabBar.translucent
透明 tabBar.barTintColor
背景颜色 tabBar.tintColor
图标被选中时颜色 selectedIndex
默认出现的页面编号
protocol
-(void) tabBarController: (UITabBarController * )tabBarController didSelectViewController:(UIViewController * )viewController
UINavigationController
通用
AppDelegate.m
#import "ViewController.h" self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; [self.window makeKeyAndVisible]; [_window release]; ViewController *vc = [[ViewController alloc] init]; // 创建导航视图控制器 UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:vc]; // 把导航视图控制器设置成window的视图控制器 self.window.rootViewController = naVC; [naVC release]; [vc release]; return YES;}- (void)dealloc{ [_window release]; [super dealloc];}
设置外观
self.navigationItem.title = @"导航栏标题";
property
- navigationController.navigationBar.translucent
影响坐标系的起点:默认 半透明YES(0, 0), 不透明NO(0, 64)
- navigationController.navigationBar.barTintColor
背景颜色
- navigationItem.title
标题
- navigationItem.titleView
标题可以用视图代替
- navigationItem.leftBarButtonItem(s)
创建左右两边的按钮(们)
- navigationItem.rightBarButtonItem
// 创建系统自带的按钮 self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(barAction:)] autorelease];// 模态跳转 view往secondView跳转- (void) buttonAction:(UIButton *) button { SecondViewController *loginVC = [[SecondViewController alloc] init]; [secVC setModalTransitionStyle: UIModalTransitionStyleCrossDissolve]; [self presentViewController: secVC animated:YES completion:^{ }];} // 按钮用自定义的图片,图片颜色固定是蓝色 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(commentAction:)]; // 用自定义视图创建按钮,让图片编程原来的颜色 UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; [myButton setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal]; myButton.frame = CGRectMake(0, 0, 40, 40); self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView: button] autorelease];
0 0
- UINavigationController,UITabBarController
- UINavigationController, UITabBarController
- UINavigationController+UITabBarController
- UINavigationController、UITabBarController
- UITabBarController UINavigationController 相结合代码
- UITabBarController UINavigationController 相结合代码
- UINavigationController与UITabBarController
- UITabBarController UINavigationController 相结合代码
- UINavigationController与UITabBarController
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController合用
- UINavigationController和UITabBarController合用。
- UINavigationController与UITabBarController
- UITabBarController inside a UINavigationController
- 隐藏UINavigationController和UITabBarController
- UINavigationController与UITabBarController
- iOS UINavigationController + UITabBarController
- UITabBarController和UINavigationController混用
- 线程间同步,条件变量
- 记一次Android ListView没有成功显示出来的原因
- 老--质价比
- .bash_profile和.bashrc的区别(如何设置生效)
- javaScript
- UINavigationController, UITabBarController
- jdbc简单操作数据库实例
- Hadoop搭建
- vdebug+xdebug安装
- 教你写响应式框架(一)
- 文件与目录(权限,操作,搜索)
- Python 使用matplotlib 画数学公式图与散点图
- C++程序设计之四书五经(为以后打折买书攒着)
- HDU 1872:稳定排序【排序】