#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的更多相关文章

  1. iOS自定义一个仿网易左右滑动切换页面框架

    FSScrollContentView github:https://github.com/shunFSKi/FSScrollContentView 这是本人在整理项目时抽离了业务代码整理封装的一个通 ...

  2. iOS自定义tabBar

    在我们的项目中经常会自己自定义tabBar因为苹果自带的真的太丑了!也不满足我们的项目需求. 好 开始行动吧! 先上图看下我们最终实现的效果: 继承UItabBar自定义一个自己的tabBar .h# ...

  3. iOS 开源一个高度可定制支持各种动画效果,支持单击双击,小红点,支持自定义不规则按钮的tabbar

    TYTabbarAnimationDemo 业务需求导致需要做一个tabbar,里面的按钮点击带有动画效果,tabbar中间的按钮凸出,凸出部分可以点击,支持badge 小红点等,为此封装了一个高度可 ...

  4. iOS 自定义Tabbar实现push动画隐藏效果

    http://wonderffee.github.io/blog/2013/08/07/hide-custom-tab-bar-with-animation-when-push/ 在之前的一篇文章(链 ...

  5. iOS 开发自定义一个提示框

    在开发的时候,会碰到很多需要提示的地方,提示的方法也有很多种,ios 8 以前的版本有alertview还是以后用的alertController,都是这种作用, 但是不够灵活,而且用的多了,用户体验 ...

  6. ios定制中间突出的tabBar

    我觉得有两个思路,一个是自己写tabBar  通过自定义实现,缺点呢就是比较麻烦,优点就是代码比较清楚,而且比较稳定. 另一个思路就是写个大按钮加在tabBar上 通过监听tabitem的点击来实现相 ...

  7. iOS 自定义TabBarController

    转自:http://blog.csdn.net/xn4545945/article/details/35994863 一.自定义的思路 iOS中的TabBarController确实已经很强大了,大部 ...

  8. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  9. iOS自定义的UISwitch按钮

    UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...

随机推荐

  1. C# - 多线程(基础)

    多线程 基础(Multithreading) 一些基本的关于线程和与其相关的概念 位)的变量赋值,这个操作就是原子性的.因为它可以一次性填充64位的二进制数据到栈上,属于一步完成,不会发生断裂.而假如 ...

  2. C++的一些小Tip

    string转数字: 一种是转换为char*后再使用atoi:atoi(s.c_str()).这个方法的神奇之处在于,如果s是负数也能顺利转化,但是,在leetcode显示,自己先判断是不是负数的话计 ...

  3. Python-form表单标签

    语义:标记表单 #1.什么是表单? 表单就是专门用来接收用户输入或采集用户信息的 #2.表单的格式 <form> <表单元素> </form> 链接:https:/ ...

  4. @Autowired mapper 层次 bean 带红线

    在利用@Autowired 注解创建bean 时候 有时间会带有下滑红色横线 给人一种报错的感觉 下面是去除红线的办法 将颜色红色error 等级降低为黄色warn  即可

  5. openwrt MT7628 编译前更改为DHCP,root 密码、ssid、时区、主机名

    一.设置为DHCP动态获取ip地址 在:/home/OpenWrt/openwrt_CC_mt76xx_zhuotk_source/ 目录下,新建文件名/files/etc/config. 将配置好的 ...

  6. jq-css、class、属性操作

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  7. 爬虫请求库之selenium模块

    一 安装 #安装:selenium+chromedriver pip3 install selenium 下载chromdriver.exe放到python安装路径的scripts目录中即可,注意最新 ...

  8. bzoj1040基环树

    ... st#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> ...

  9. 使用AltSearch格式化Kindle读书笔记

    AltSearch是LibreOffice Writer的一个用于自动化执行复杂文本替换操作的扩展,能够在不需要复杂编程的条件下进行一些文档格式的手动与批量转换和调整.该扩展除了支持普通文本与正则表达 ...

  10. javaAPI实现elasticsearch5.5.2的聚合分析

    https://blog.csdn.net/plei_yue/article/details/78452633