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的结 ...
随机推荐
- 使用python发送和接收邮件
关于电子邮件 大学之前,基本不用邮箱,所以基本感觉不到它的存在,也不知道有什么用:然而大学之后,随着认识的人越来越多,知识越来越广泛,邮箱已然成为很重要的通讯工具,大学一些课程作业需要有邮箱发给老师, ...
- DDD开发框架ABP之本地化资源的数据库存储扩展
在上一篇<DDD开发框架ABP之本地化/多语言支持>中,我们知道,ABP开发框架中本地化资源存储可以采用XML文件,RESX资源文件,也提供了其他自定义的存储方式的扩展接口.ABP框架默认 ...
- Lind.DDD.IoC依赖注入与面向方面的实现
回到目录 IoC是解耦的灵魂,很难想像一个框架中没有IoC会变成什么样子,Lind.DDD里的IoC是通过Unity实现的,由依赖注入(unity)和方法拦截组成(Interception),依赖注入 ...
- git将本地仓库推送到远程仓库
如何将本地仓库推送到公司远程仓库? 1:前提是你本地安装好git.先把远程git仓库克隆到本地 git clone 远程仓库的地址(SSH) 2: git branch //查看本地分支 3: g ...
- angularjs—指令input
input[text] input一般和ngModel结合使用来实现双向绑定,同时angular提供了很多表单校验的指令 required 必填 ngRequired 必填(ngRequired可以控 ...
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(三)显示地图坐标系模块
config.xml文件的配置如下: <widget left="3" bottom="3" config="widgets/Coordinat ...
- iOS 线程安全之@synchronized的用法
@synchronized(self)的用法: @synchronized 的作用是创建一个互斥锁,保证此时没有其它线程对self对象进行修改.这个是objective-c的一个锁定令牌,防止self ...
- 显示快照监控:/SDF/MON
透过SE38运行程序/SDF/MON,可以显示屏幕的监控快照:
- Fragment与ViewPager
众所周知,为了实现滑动界面,经常让Fragment与ViewPager一起结合使用,每一个ViewPager的页面就是一个Fragment,我们可以在fragment中实现丰富的功能.它的基本用法可以 ...
- 使用Objective-C 计算代码运行时间
第一种:(最简单的NSDate) NSDate* tmpStartData = [NSDate date]; //You code here... double deltaTime = [[NSDat ...