UITabBarController的创建与自定义TarBar---学习笔记三


代码如下:
#import <UIKit/UIKit.h> @interface BSJTabBarViewController : UITabBarController @end
#import "BSJTabBarViewController.h"
#import "BSJTabBar.h"
@interface BSJTabBarViewController () @end @implementation BSJTabBarViewController #pragma mark --- life cycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// self.tabBarItem = [UITabBarItem application]
UITabBarItem *tabBarItem = [UITabBarItem appearance];
//未选中的
NSMutableDictionary *norAttri = [NSMutableDictionary dictionary];
norAttri[NSFontAttributeName] = [UIFont systemFontOfSize:14];
norAttri[NSForegroundColorAttributeName] = [UIColor grayColor];
[tabBarItem setTitleTextAttributes:norAttri forState:UIControlStateNormal];
//选中的
NSMutableDictionary *selectAttri = [NSMutableDictionary dictionary];
selectAttri[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
[tabBarItem setTitleTextAttributes:selectAttri forState:UIControlStateSelected]; //精华
[self setupChridViewController:[[UITableViewController alloc] init] title:NSLocalizedString(@"精华", nil) normalImage:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
[self setupChridViewController:[[UIViewController alloc] init] title:NSLocalizedString(@"关注", nil) normalImage:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
[self setupChridViewController:[[UITableViewController alloc] init] title:NSLocalizedString(@"新帖", nil) normalImage:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
[self setupChridViewController:[[UITableViewController alloc] init] title:NSLocalizedString(@"我", nil) normalImage:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
// 通过KVC,可以改变属性为readOnly,改变它的Key,也就是通过它的value找到它的key
[self setValue:[[BSJTabBar alloc] init] forKey:@"tabBar"];
} - (void)setupChridViewController:(UIViewController *)vc title:(NSString *)title normalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage{ vc.title = title;
if (normalImage.length && selectedImage.length )
{ vc.tabBarItem.image = [UIImage imageNamed:normalImage];
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage]; }
[self addChildViewController:vc]; } //tabBar #import <UIKit/UIKit.h>
@interface BSJTabBar : UITabBar
@end #import "BSJTabBar.h" @interface BSJTabBar() @property (nonatomic, weak)UIButton *publicButton; @end
@implementation BSJTabBar
- (void)layoutSubviews{ [super layoutSubviews]; // BSJLogFunc CGFloat buttonW = self.frame.size.width/5;
CGFloat buttonH = self.frame.size.height;
CGFloat buttonY = 0;
CGFloat i = 0;
for (UIView *subView in self.subviews)
{ BSJLog(@"%@",NSStringFromClass(subView.class));
// if (![subView.class isSubclassOfClass:[NSClassFromString(@"UITabBarButton") class]]) continue; if (![@"UITabBarButton" isEqualToString:NSStringFromClass(subView.class)]) continue; CGFloat buttonX = i*buttonW; if (i >= 2) { buttonX += buttonW; } subView.frame = CGRectMake(buttonX, buttonY, buttonW, buttonH); i++; }
// [
self.publicButton setFrame:CGRectMake(0, 0, self.frame.size.width/5, self.frame.size.height)];
//
self.publicButton.center = CGPointMake(self.center.x, self.center.y);
}
#pragma mark --- response methods
- (void)buttonClick:(UIButton *)sender{
} #pragma mark --- setters and getters
- (UIButton *)publicButton{
if (!_publicButton)
{ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button]; _publicButton = button; } return _publicButton;
}
@end
UITabBarController的创建与自定义TarBar---学习笔记三的更多相关文章
- [Firefly引擎][学习笔记三][已完结]所需模块封装
原地址:http://www.9miao.com/question-15-54671.html 学习笔记一传送门学习笔记二传送门 学习笔记三导读: 笔记三主要就是各个模块的封装了,这里贴 ...
- angular学习笔记(三十)-指令(6)-transclude()方法(又称linker()方法)-模拟ng-repeat指令
在angular学习笔记(三十)-指令(4)-transclude文章的末尾提到了,如果在指令中需要反复使用被嵌套的那一坨,需要使用transclude()方法. 在angular学习笔记(三十)-指 ...
- openresty 学习笔记三:连接redis和进行相关操作
openresty 学习笔记三:连接redis和进行相关操作 openresty 因其非阻塞的调用,令服务器拥有高性能高并发,当涉及到数据库操作时,更应该选择有高速读写速度的redis进行数据处理.避 ...
- Oracle学习笔记三 SQL命令
SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)
- JSP学习笔记(三):简单的Tomcat Web服务器
注意:每次对Tomcat配置文件进行修改后,必须重启Tomcat 在E盘的DATA文件夹中创建TomcatDemo文件夹,并将Tomcat安装路径下的webapps/ROOT中的WEB-INF文件夹复 ...
- VSTO学习笔记(三) 开发Office 2010 64位COM加载项
原文:VSTO学习笔记(三) 开发Office 2010 64位COM加载项 一.加载项简介 Office提供了多种用于扩展Office应用程序功能的模式,常见的有: 1.Office 自动化程序(A ...
- Java IO学习笔记三
Java IO学习笔记三 在整个IO包中,实际上就是分为字节流和字符流,但是除了这两个流之外,还存在了一组字节流-字符流的转换类. OutputStreamWriter:是Writer的子类,将输出的 ...
- 学习笔记(三)--->《Java 8编程官方参考教程(第9版).pdf》:第十章到十二章学习笔记
回到顶部 注:本文声明事项. 本博文整理者:刘军 本博文出自于: <Java8 编程官方参考教程>一书 声明:1:转载请标注出处.本文不得作为商业活动.若有违本之,则本人不负法律责任.违法 ...
- muduo网络库学习笔记(三)TimerQueue定时器队列
目录 muduo网络库学习笔记(三)TimerQueue定时器队列 Linux中的时间函数 timerfd简单使用介绍 timerfd示例 muduo中对timerfd的封装 TimerQueue的结 ...
随机推荐
- Linux实战问题解决方案(1):Could not get lock
环境: Ubuntu12.04 问题描述: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily un ...
- JQuery实现一个简单的鼠标跟随提示效果
效果体验:http://hovertree.com/texiao/jsstudy/2/ 实现思路 1 鼠标移入标题(这里是<a>标签) 创建一个div,div的内容为鼠标位置的文本 将创建 ...
- 设置statusBarStyle
设置状态栏的样式, typedef NS_ENUM(NSInteger, UIStatusBarStyle) { UIStatusBarStyleDefault ...
- 深入剖析通知中心和KVO
深入剖析通知中心和KVO 要先了解KVO和通知中心,就得先说说观察者模式,那么观察者模式到底是什么呢?下面来详细介绍什么是观察者模式. 观察者模式 -A对B的变化感兴趣,就注册成为B的观察者,当B发生 ...
- iOS开发之功能模块--高仿Boss直聘的IM界面交互功能
本人公司项目属于社交类,高仿Boss直聘早期的版本,现在Boss直聘界面风格,交互风格都不如Boss直聘以前版本的好看. 本人通过iPhone模拟器和本人真机对聊,将完成的交互功能通过Mac截屏模拟器 ...
- C# .net dotnet属性定义属性,以提供显示明称,默认值
//使用显示名称初始化 System.ComponentModel.DisplayNameAttribute 类的新实例. displayName 显示名称 [DisplayName("we ...
- SQL SERVER 2000 迁移后SQL SERVER代理服务启动错误分析
公司有一个老系统,这个系统所用的数据库是SQL SERVER 2000,它所在的Dell服务器已经运行超过10年了,早已经过了保修服务期,最近几乎每周会出现一次故障,加之5月份另外一台服务器坏了两个硬 ...
- 记录一次MongoDB3.0.6版本wiredtiger与MMAPv1引擎的写入耗时对比
一.MongoDB3.0.x的版本特性(相对于MongoDB2.6及以下): 增加了wiredtiger引擎: 开源的存储引擎: 支持多核CPU.充分利用内存/芯片级别缓存(注:10月14日刚刚发布的 ...
- android 发送短信功能
private void sendSMS(String num,String smsBody) { String phoneNum = "smsto:" + num; Uri sm ...
- 012.对netmap API的解读
一.简要说明: 1.netmap API主要为两个头文件netmap.h 和netmap_user.h ,当解压下载好的netmap程序后,在./netmap/sys/net/目录下,本文主要对这两个 ...