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] ...
随机推荐
- 解决-webkit-box-orient: vertical;(文本溢出)属性在webpack打包后无法编译的问题
在scss里面: /*! autoprefixer: off */-webkit-box-orient: vertical;/* autoprefixer: on */
- windows :config windows update … 一直处于假死状态
参考文章:http://www.cnblogs.com/teacat/p/9204225.html 环境:win7 64bit 旗舰版 问题:重启后,系统更新到35%后,一直处于假死状态,未能正确进入 ...
- 51nod--1072 威佐夫游戏 (博弈论)
题目: 1072 威佐夫游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取相同 ...
- python selenium Chrome模拟手机浏览器
在做移动端页面测试时可以利用Chrome mobile emulation 辅助完成页面的适配问题,但是目前手机市场上的型号居多我们也没有办法通过人工的模式一一的去适配,所以这里考虑到通过自动化的模式 ...
- Python学习笔记四
一.装饰器 1.知识储备 函数对象 函数可以被引用 函数可以当参数传递 返回值可以是函数 可以当作容器的元素 def func1(): print (666) def func2(): print ( ...
- Redis实战 - 1.String和计数器
在.NET Core 项目中操练String 使用 StackExchange.Redis 访问 Redis static void Main(string[] args) { using (Conn ...
- Swift 统计项目中所有按钮的点击次数
class Swizzle: NSObject { override class func load() { UIButton.xxx_swizzleSendAction() } } extensio ...
- Java 使用blob对H5视频播放进行加密《java视频加密》
1.创建一个H5 <video>标签 <video id="sound" type="video/mp4" controls="co ...
- CSS属性兼容写法
一种是用js判断兼容性 // JS if ("CSS" in window && "supports" in window.CSS) { var ...
- [Web]Restful风格的适用场景
最近一直在兜兜转转Restful的相关内容,准备在原先的项目上构建restful的API. 实践过程很别扭,直到看到这篇文章[A Brief Introduction to REST], 我才终于断定 ...