[iOS微博项目 - 1.6] - 自定义TabBar
- 选中时item字体颜色为蓝色


- (void)viewDidAppear:(BOOL)animated {
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
attr[NSForegroundColorAttributeName] = [UIColor orangeColor];
for (UITabBarItem *item in self.tabBar.items) {
[item setTitleTextAttributes:attr forState:UIControlStateSelected];
}
}

- 封装上述的改变TabBarButton文本颜色的代码
- 重写TabBarButton的位置尺寸,中间空出一个位置放置“+”按钮
//
// HVWTabBar.m
// HVWWeibo
//
// Created by hellovoidworld on 15/2/3.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWTabBar.h" @implementation HVWTabBar - (void)layoutSubviews {
// 切记一定要调用父类的方法!!!
[super layoutSubviews]; // 设置文本属性
[self initTextAttr]; // 设置BarButton的位置
[self initBarButtonPosition]; // 添加"+"按钮
[self addComposeButton];
} /** 设置文本属性 */
- (void) initTextAttr {
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
attr[NSForegroundColorAttributeName] = [UIColor orangeColor]; for (UITabBarItem *item in self.items) {
// 设置字体颜色
[item setTitleTextAttributes:attr forState:UIControlStateSelected];
}
} /** 设置BarButton的位置 */
- (void) initBarButtonPosition { // 创建一个位置所以,用来定位
int index = ; for (UIView *tabBarButton in self.subviews) {
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
// 计算尺寸,预留一个“+”号空间
CGFloat width = self.width / (self.items.count + );
tabBarButton.width = width; // 计算位置
if (index < (int)(self.items.count / )) {
tabBarButton.x = width * index;
} else {
tabBarButton.x = width * (index + );
} index++;
}
}
} /** 添加"+"按钮 */
- (void) addComposeButton {
// 初始化按钮
UIButton *plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setBackgroundImage:[UIImage imageWithNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
[plusButton setBackgroundImage:[UIImage imageWithNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
[plusButton setImage:[UIImage imageWithNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
[plusButton setImage:[UIImage imageWithNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted]; // 设置位置尺寸
CGFloat width = self.width / (self.items.count + );
CGFloat height = self.height;
CGFloat x = (self.items.count / ) * width;
CGFloat y = ;
plusButton.frame = CGRectMake(x, y, width, height); // 添加到tabBar上
[self addSubview:plusButton];
} @end

- 弹出一个新的界面用来写新微博
- 新建一个目录“compose”专门负责发微博业务
- 创建一个集成UIViewController的HVWComposeViewController
//
// HVWComposeViewController.m
// HVWWeibo
//
// Created by hellovoidworld on 15/2/3.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWComposeViewController.h" @interface HVWComposeViewController () @end @implementation HVWComposeViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. // 初始化一些功能按钮
self.view.backgroundColor = [UIColor redColor];
self.title = @"+号弹出控制器"; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"退出" style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
} - (void) dismiss {
[self dismissViewControllerAnimated:YES completion:nil]; } @end
// HVWTabBarViewController.m
#pragma mark - HVWTabBarDelegate
/** “+”按钮点击代理方法 */
- (void)tabBarDidComposeButtonClick:(HVWTabBar *)tabBar {
HVWComposeViewController *composeView = [[HVWComposeViewController alloc] init]; // tabBarController不是由navigationController弹出来的,没有navigationController
// [self.navigationController pushViewController:vc animated:YES];
// HVWLog(@"%@", self.navigationController); // null // 为了使用导航栏,使用NavigationController包装一下
HVWNavigationViewController *nav = [[HVWNavigationViewController alloc] initWithRootViewController:composeView];
// 使用modal方式弹出
[self presentViewController:nav animated:YES completion:nil];
}

[iOS微博项目 - 1.6] - 自定义TabBar的更多相关文章
- iOS开发项目之四 [ 调整自定义tabbar的位置与加号按钮的位置]
自定义tabbar与按钮的添加 01 - 把系统的tabbar用我们自己的覆盖 LHQTabBar *lhqTabBar = [[LHQTabBar alloc]init]; [self setVal ...
- [iOS微博项目 - 4.0] - 自定义微博cell
github: https://github.com/hellovoidworld/HVWWeibo A.自定义微博cell基本结构 1.需求 创建自定义cell的雏形 cell包含:内容.工具条 内 ...
- [iOS微博项目 - 1.4] - 各种item NavigationBar & NavigationItem & BarButtonItem || TabBar & TabBarItem
一.UINavigationItem1> 获得方式self.navigationItem // self是指控制器2> 作用可以用来设置当前控制器顶部导航栏的内容// 设置导航栏中间的内容 ...
- [iOS微博项目 - 1.0] - 搭建基本框架
A.搭建基本环境 github: https://github.com/hellovoidworld/HVWWeibo 项目结构: 1.使用代码构建UI,不使用storyboard ...
- [iOS微博项目 - 3.6] - 获取未读消息
github: https://github.com/hellovoidworld/HVWWeibo A.获取登陆用户未读消息 1.需求 获取所有未读消息,包括新微博.私信.@.转发.关注等 把未 ...
- [iOS微博项目 - 3.1] - 发微博界面
github: https://github.com/hellovoidworld/HVWWeibo A.发微博界面:自定义UITextView 1.需求 用UITextView做一个编写微博的输 ...
- [iOS微博项目 - 3.0] - 手动刷新微博
github: https://github.com/hellovoidworld/HVWWeibo A.下拉刷新微博 1.需求 在“首页”界面,下拉到一定距离的时候刷新微博数据 刷新数据的时候使 ...
- [iOS微博项目 - 1.7] - 版本新特性
A.版本新特性 1.需求 第一次使用新版本的时候,不直接进入app,而是展示新特性界面 github: https://github.com/hellovoidworld/HVWWeibo ...
- [iOS微博项目 - 1.1] - 设置导航栏主题(统一样式)
A.导航栏两侧文字按钮 1.需求: 所有导航栏两侧的文字式按钮统一样式 普通样式:橙色 高亮样式:红色 不可用样式:亮灰 阴影:不使用 字体大小:15 github: https://github ...
随机推荐
- openfire中mysql的前期设置
使用openfire的时候如果需要使用自己的mysql数据库,需要提前进行设置,下面将记录下,基本的设置过程. 一.前期准备工作: 1.先下载两个工具一个是mysql数据库还有一个是SQLyog(可以 ...
- Android应用程序中应用图标和名字的设置
在AndroidManifest.xml文件中设android:icon和 android:label指定名字和图标的位置,如: <application android:icon=" ...
- gulp.watch监听文件
Gulp.watch()会返回我们熟知的watcher.我们可以利用watcher来监听额外的事件或者向watch中添加文件. 例如,在执行一系列任务和调用一个函数时,你就可以在返回的watcher中 ...
- Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1
Reference link: http://unix.stackexchange.com/questions/70963/difference-between-2-2-dev-null-dev-nu ...
- BZOJ3856: Monster
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3856 题解:怎么乱搞一下都可以把 代码: #include<cstdio> #in ...
- IPicture、BITMAP、HBITMAP和CBitmap的关系
1.有关IPicture加载图片后直接Render到内存DC的问题(HBITMAP转换IPicture)Picture的方法get_Handle可以直接得到图片的句柄 IPicture *pIPict ...
- 学习Mongodb(一)
图片摘录自陈彦铭出品2012.5的<10天掌握MongDB> MongoDB的特点--->面向集合存储,易于存储对象类型的数据--->模式自由--->支持动态查询---& ...
- 【转】移动web资源整理
目录(更新于20150311) meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 忽略将页面中的数字识别为电话号码 忽略Android平台中对邮箱地址的识别 当网站添加到主屏幕快速 ...
- css的伪元素
这里想将的是两个伪元素,一个是:first-line——用来向文本的首行添加特殊样式,并且不论该行出现多少单词:只能与块状元素关联. 如下属性可以应用于:first-line伪元素 font属性 co ...
- android view的setVisibility方法值的意思
android view的setVisibility方法值的意思 有三个值 visibility One of VISIBLE, INVISIBLE, or GONE. 常量值为0,意思是可见的 常 ...