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] ...
随机推荐
- 基于 Webhooks gitlab 自动化构建
基于gitlab webhooks 自动构建流程 1.服务器安装 git 服务 安装成功 配置 PHP 脚本: <?php // 接受头部信息 if (!isset($_GET['youpara ...
- Linux进程组调度机制分析【转】
转自:http://oenhan.com/task-group-sched 又碰到一个神奇的进程调度问题,在系统重启过程中,发现系统挂住了,过了30s后才重新复位,真正系统复位的原因是硬件看门狗重启的 ...
- 转:对UI自动化测试的一些感悟
不断发掘自动化测试对各个团队的附加价值,这样才能得到来自四面八方的支持,没有将自动化加入项目过程的自动化都达不到预期的效果. UI自动化框架 把UI自动化框架设计成一个拼图性质的架构.把每个特性都设计 ...
- Android开发之字体设置
默认字体 Android SDK自带了四种字体:"normal"“monospace",“sans”, “serif”,如下: 字体 看这四兄弟长的还是蛮像,我是看不 ...
- linux基础一篇就够了
Linux学习笔记 粗略笔记第一版,全文约2000行50000字 1. 时间和日历 date:查看当前时间 cal:查看当月日历 cal 2018:查看年日历 cal 10 2018:指定某年某月日历 ...
- swiper2 swiper-slide 之间的间距调整
1.在css中调整间距(我的这个是一行显示三个) swiper-slide-active 可以对这个类进行操作 这个类是显示在页面上的第一个元素 2.设置js //热门新闻 swiper var ne ...
- Jmeter性能测试之基础知识(一)
1. 官网下载Jmeter: 点这里, 下载完成解压即可 2. 启动: 进入解压后的bin目录, Windows点击jmeter.bat, Linux执行jmeter 3. 添加线程组(user) : ...
- js判断是否在微信中打开
var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger&quo ...
- 使用Type.MakeGenericType,反射构造泛型类型
有时我们会有通过反射来动态构造泛型类型的需求,该如何实现呢?举个栗子,比如我们常常定义的泛型委托Func<in T, out TResult>,当T或TResult的类型需要根据程序上下文 ...
- C++ vector的用法(整理)
vector 是向量类型,它可以容纳许多类型的数据,如若干个整数,所以称其为容器.vector 是C++ STL的一个重要成员,使用它时需要包含头文件: #include<vector>; ...