一、快速切换文件
com+shift+o
二、使用Quick Help代码
三、设置渲染模式,使TabBar上的图片显示原始状态
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
四、appearence
UITabBar *tabBar = [UITabBar appearence];
五、layoutSubViews
父视图的子视图有变化就会调用此方法
比如addsubView
六、打印frame
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
七、
- (UIImage *)imageWithColor:(UIColor *)color
八、NavigationController
1.所有ViewController共用1个NavigationBar
2.每一个VC都有1个自己的NavigationItem(Left、Right、title)
每一个在导航中的VC内部,都可以self.navigationController获得NavigationController
九、TabBarController
1.所有ViewController共用1个UITabBar
2.每一个VC都有1个自己的TabBarItem
每一个在TabBarController中的VC内部,都可以self.tabBarController获得TabBarController
步骤:
1.创建UITabBarController
2.创建ViewController
3.创建tabBarItem
3.1.系统tabbar
3.2.自定义TabBarItem
4.添加到tabBarCtr
5.添加代理
6.其他设置
7.设置根视图控制器
源码:
1.创建UITabBarController
tabBarCtr = [[UITabBarController alloc]init];
2.创建ViewController
RedViewController *redVC = [[RedViewController alloc]init];
3.创建tabBarItem
3.1.系统tabbar
3.2.自定义TabBarItem
redVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"主页" image:[UIImage imageNamed:@"tab_feed"] selectedImage:[UIImage imageNamed:@"tab_feed"]];
4.添加到tabBarCtr
tabBarCtr.viewControllers = @[redVC,greenVC,yellowVC1,blueVC,yellowVC];
5.添加代理
tabBarCtr.delegate = self;
6.其他设置
设置选中位置
tabBarCtr.selectedIndex = 3;
添加按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[tabBarCtr.view addSubview:button];
7.设置根视图控制器
self.window.rootViewController = tabBarCtr;
#pragma mark - **************** tabBarController 协议方法
#pragma mark tabBarController将要选中某个视图,询问是否跳转
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
#pragma mark 选中后调用
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
注意:
//渲染图片
UIImage *image = [UIImage imageNamed:@"tabbar_home"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//改变文字颜色
tabBarCtr.tabBar.tintColor = [UIColor yellowColor];
//改变TabBar的背景
tabBarCtr.tabBar.barTintColor = [UIColor blackColor];
测试:自己写一个自定义类
实现新浪微博TabBar
Home: tabbar_home, tabbar_home_selected
Message: tabbar_message_center, tabbar_message_center_selected
Compose: tabbar_compose_button, tabbar_compose_icon_add_highlighted(默认)
Discover: tabbar_discover, tabbar_discover_selected
Profile: tabbar_profile, tabbar_profile_highlighted