[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 ...
随机推荐
- LA 5009 (三分法求极值) Error Curves
给出的曲线要么是开口向上的抛物线要么是直线,但所定义的F(x)的图形一定是下凸的. 注意一点就是求得是极小值,而不是横坐标,样例也很容易误导人. #include <cstdio> #in ...
- tomcat 默认项目设置
正常情况下,我们启动tomcat后,直接输入“http://localhost:端口/“ 后,默认访问道是webapp目录下的ROOT应用. 我们要通过上述方式访问自己的应用,有俩种方式. 第一:把自 ...
- 基于RTP的H264视频数据打包解包类
from:http://blog.csdn.net/dengzikun/article/details/5807694 最近考虑使用RTP替换原有的高清视频传输协议,遂上网查找有关H264视频RTP打 ...
- Android 下压缩图片—微弱失真
Android下压缩图片的方法: 大概能将3M左右的图片压缩到100K左右, 几乎不失真. 代码如下: import java.io.FileNotFoundException; import jav ...
- Spring学习之Ioc
Ioc原理讲解:http://www.cnblogs.com/xdp-gacl/p/4249939.html Ioc IoC是一种编程思想,由主动编程变为被动接收. 也就是说,所有的组件都是被动的(p ...
- ViewPager设置 缓存个数、页卡间距、数据更新
在使用ViewPager常用设置 1)mViewPager.setOffscreenPageLimit(2);//设置缓存view 的个数(实际有3个,缓存2个+正在显示的1个)2)mViewPage ...
- OutputCache缓存各参数的说明
Duration 缓存时间,以秒为单位,这个除非你的Location=None,可以不添加此属性,其余时候都是必须的. Location Location当被设置为None时,其余的任何设置将不起作用 ...
- [转] WinForm自定义函数FindControl实现按名称查找控件
原文地址 WinForm自定义函数FindControl实现按名称查找控件 本文所述实例实现WinForm自定义函数FindControl实现按名称查找控件的功能,在C#程序开发中有一定的实用价值. ...
- 链表的倒数第K个节点
题目:输入一个链表,输出该链表中倒数第K个节点.为了符合大多数人的习惯,本题从1开始计数,即链表的尾节点是倒数第1个结点. package com.edu; class LinkNode{ //定义一 ...
- 2016计蒜之道复赛 百度地图的实时路况 floyd+cdq分治
链接:https://nanti.jisuanke.com/t/11217 奉上官方题解: 枚举 d(x , y , z) 中的 y,把 y 从这个图中删去,再求这时的全源最短路即可,使用 Floyd ...