UINavigationController, UITabBarController
2016-03-13 12:23
435 查看
UITabBarController
通用
AppDelegate.mself.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 * )viewControllerUINavigationController
通用
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];
相关文章推荐
- android 6.0 SystemUI源码分析(6)-StorageNotification介绍
- com.mchange.v2.resourcepool.CannotAcquireResourceException
- com.mchange.v2.resourcepool.CannotAcquireResourceException
- (4.2.25)22个值得收藏的Android开源代码-UI篇
- 关于Android的Build类——获取Android手机设备各种信息
- UIScrollView、UIPageControl、NSTimer
- JDBC连接执行 MySQL 存储过程报权限错误:User does not have access to metadata required to determine stored procedur
- 通过代理更新UITableHeaderFooterView某一行数据时,如何获取更新哪一行的
- C#中String与StringBuilder的区别
- 设置为我们的UITableViewFooterHeaderView组标题的高度
- 为我们的UITableViewFooterHeaderView添加自定义View的布局
- 为我们的UITableViewFooterHeaderView设置某一行或所有的行高度
- 设置UITableViewHeaderFooterView的背景颜色
- 自定义UITableViewFooterHeaderView时调用自身的self.bounds为0的情况
- UITableViewHeaderFooterView当中的方法
- android studio authentication required解决方案
- PB 导入和导出Excel
- 改进后的快速排序--ImprovedQuickSort
- UIControl 详解
- Youth by Samuel Ullman