iOS 自定义一个常规的TabBar
#import "WJWBaseTabBarViewController.h"
#import "WJWTabBarButton.h"
#import "WJWMainViewController.h"
#import "WJWDiscoverViewController.h"
#import "WJWMyViewController.h"
@interface WJWBaseTabBarViewController ()
@property (nonatomic, weak) UIButton *selectedBtn;
@end
@implementation WJWBaseTabBarViewController
+ (void)load {
UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor blackColor];
[item setTitleTextAttributes:attrs forState:UIControlStateSelected];
NSMutableDictionary *attrsFontNormal = [NSMutableDictionary dictionary];
attrsFontNormal[NSFontAttributeName] = [UIFont systemFontOfSize:13];
[item setTitleTextAttributes:attrs forState:UIControlStateSelected];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self configAllSunTabs];
[self setAllTabBarItems];
}
- (void)configAllSunTabs {
WJWMainViewController *mainVC = [[WJWMainViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:mainVC];
[self addChildViewController:nav1];
WJWDiscoverViewController *disVC = [[WJWDiscoverViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:disVC];
[self addChildViewController:nav2];
WJWMyViewController *myVC = [[WJWMyViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:myVC];
[self addChildViewController:nav3];
}
- (void)setAllTabBarItems {
NSArray *normalBtnArray = @[@"home_normal",@"faxian_normal",@"shequ_normal",@"haoyou_normal",@"wode_normal"];
NSArray *highlightBtnArray = @[@"home_highlight",@"faxian_highlight",@"shequ_highlight",@"haoyou_highlight",@"wode_highlight"];
NSArray *titleArray = @[@"首页",@"发现",@"社区",@"好友",@"我的"];
UINavigationController *nav1 = self.childViewControllers[0];
nav1.tabBarItem.title = titleArray[0];
nav1.tabBarItem.image = [UIImage imageNamed:normalBtnArray[0]];
nav1.tabBarItem.selectedImage = [UIImage imageNamed:highlightBtnArray[0]];
UINavigationController *nav2 = self.childViewControllers[1];
nav2.tabBarItem.title = titleArray[1];
nav2.tabBarItem.image = [UIImage imageNamed:normalBtnArray[1]];
nav2.tabBarItem.selectedImage = [UIImage imageNamed:highlightBtnArray[1]];
UINavigationController *nav3 = self.childViewControllers[2];
nav3.tabBarItem.title = titleArray[4];
nav3.tabBarItem.image = [UIImage imageNamed:normalBtnArray[4]];
nav3.tabBarItem.selectedImage = [UIImage imageNamed:highlightBtnArray[4]];
}
- (void)viewDidLayoutSubviews {
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
AppDelegete.m 中把tabBarController设置为 window的根控制器。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
WJWBaseTabBarViewController *baseTabBar = [[WJWBaseTabBarViewController alloc] init];
self.window.rootViewController = baseTabBar;
[self.window makeKeyAndVisible];
return YES;
}
iOS 自定义一个常规的TabBar的更多相关文章
- iOS自定义一个仿网易左右滑动切换页面框架
FSScrollContentView github:https://github.com/shunFSKi/FSScrollContentView 这是本人在整理项目时抽离了业务代码整理封装的一个通 ...
- iOS自定义tabBar
在我们的项目中经常会自己自定义tabBar因为苹果自带的真的太丑了!也不满足我们的项目需求. 好 开始行动吧! 先上图看下我们最终实现的效果: 继承UItabBar自定义一个自己的tabBar .h# ...
- iOS 开源一个高度可定制支持各种动画效果,支持单击双击,小红点,支持自定义不规则按钮的tabbar
TYTabbarAnimationDemo 业务需求导致需要做一个tabbar,里面的按钮点击带有动画效果,tabbar中间的按钮凸出,凸出部分可以点击,支持badge 小红点等,为此封装了一个高度可 ...
- iOS 自定义Tabbar实现push动画隐藏效果
http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...
- iOS 开发自定义一个提示框
在开发的时候,会碰到很多需要提示的地方,提示的方法也有很多种,ios 8 以前的版本有alertview还是以后用的alertController,都是这种作用, 但是不够灵活,而且用的多了,用户体验 ...
- ios定制中间突出的tabBar
我觉得有两个思路,一个是自己写tabBar 通过自定义实现,缺点呢就是比较麻烦,优点就是代码比较清楚,而且比较稳定. 另一个思路就是写个大按钮加在tabBar上 通过监听tabitem的点击来实现相 ...
- iOS 自定义TabBarController
转自:http://blog.csdn.net/xn4545945/article/details/35994863 一.自定义的思路 iOS中的TabBarController确实已经很强大了,大部 ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
随机推荐
- 找不多控件, or 控件为null
组件化开发,命名要使用moudle区分, 同名,在最后合成的时候,会出现很多问题,
- CF1119A Ilya and a Colorful Walk
题目地址:CF1119A Ilya and a Colorful Walk \(O(n^2)\) 肯定过不掉 记 \(p_i\) 为从下标 \(1\) 开始连续出现 \(i\) 的个数 那么对于每一个 ...
- 【译】索引进阶(一):SQL SERVER索引介绍
[译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:http://www.sqlservercentral.com/articles/Stairway+Series/7 ...
- ASP.NET Core之依赖注入
本文翻译自:http://www.tutorialsteacher.com/core/dependency-injection-in-aspnet-core ASP.NET Core支持依赖注入,依赖 ...
- PID控制器开发笔记之十三:单神经元PID控制器的实现
神经网络是模拟人脑思维方式的数学模型.神经网络是智能控制的一个重要分支,人们针对控制过程提供了各种实现方式,在本节我们主要讨论一下采用单神经元实现PID控制器的方式. 1.单神经元的基本原理 单神经元 ...
- unity 如何在botton AddListen中传递参数调用函数
使用Deleget方法包含该函数即可. levelItem.GetComponent<Toggle().onValueChanged.AddListener(SetSelectedLevel(l ...
- 开发快捷键(Eclipse,STS)
Eclipse 常用快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] 此快捷键为 ...
- Windows Internals 笔记——内核对象
1.每个内核对象都只是一个内存块,它由操作系统内核分配,并只能由操作系统内核访问.这个内存块是一个数据结构,其成员维护着与对象相关的信息. 2.调用一个会创建内核对象的函数后,函数会返回一个句柄,它标 ...
- 树上背包O(n*m^2)|| 多叉树转二叉树 || o(n*m)???
#. 选课 描述 提交 自定义测试 问题描述 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有 ...
- JAVA 动态代理原理和实现
在 Java 中动态代理和代理都很常见,几乎是所有主流框架都用到过的知识.在面试中也是经常被提到的话题,于是便总结了本文. Java动态代理的基本原理为:被代理对象需要实现某个接口(这是前提),代理对 ...