A.每条微博的底部工具条
1.需求
  • 每条微博底部都有一个工具条
  • 显示3个按钮:评论、转发、赞
  • 按钮间用分割线隔开
  • 有评论数、转发数、赞数的时候显示相应数据,没有则显示文本
 
 
2.思路
(略)
 
3.实现
 
(1)微博数据模型中已经带有了相应数据字段
 //  HVWStatus.h
/** int 转发数 */
@property(nonatomic, assign) int reposts_count; /** int 评论数 */
@property(nonatomic, assign) int comments_count; /** int 表态数 */
@property(nonatomic, assign) int attitudes_count;
 
(2)直接在toolbar view中,在设置status数据的时候处理
 //
// HVWStatusToolbar.m
// HVWWeibo
//
// Created by hellovoidworld on 15/2/12.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWStatusToolbar.h" @interface HVWStatusToolbar() /** 按钮数组 */
@property(nonatomic, strong) NSMutableArray *buttons; /** 分割线数组 */
@property(nonatomic, strong) NSMutableArray *divides; /** 转发按钮 */
@property(nonatomic, strong) UIButton *repostButton; /** 评论按钮 */
@property(nonatomic, strong) UIButton *commentButton; /** 点赞按钮 */
@property(nonatomic, strong) UIButton *attitudeButton; @end @implementation HVWStatusToolbar - (NSMutableArray *)buttons {
if (nil == _buttons) {
_buttons = [NSMutableArray array];
}
return _buttons;
} - (NSMutableArray *)divides {
if (nil == _divides) {
_divides = [NSMutableArray array];
}
return _divides;
} /** 代码自定义初始化方法 */
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame]; if (self) {
// 设置toolbar背景
self.image = [UIImage resizedImage:@"timeline_card_bottom_background"]; // 为了按钮能够点击,设置父控件可交互
self.userInteractionEnabled = YES; // 添加按钮
self.commentButton = [self setupButtonWithIcon:@"timeline_icon_comment" title:@"评论"];
self.repostButton = [self setupButtonWithIcon:@"timeline_icon_retweet" title:@"转发"];
self.attitudeButton = [self setupButtonWithIcon:@"timeline_icon_unlike" title:@"赞"]; // 添加分割线
[self setupDivides];
} return self;
} // 设置按钮
- (UIButton *) setupButtonWithIcon:(NSString *)icon title:(NSString *)title {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// 标题
[button setTitle:title forState:UIControlStateNormal];
// 图片
[button setImage:[UIImage imageWithNamed:icon] forState:UIControlStateNormal];
// 字体颜色
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
// 字体大小
button.titleLabel.font = [UIFont systemFontOfSize:];
// 图标、文本之间间隙
[button setTitleEdgeInsets:UIEdgeInsetsMake(, , , )];
// 高亮背景
[button setBackgroundImage:[UIImage imageWithNamed:@"timeline_card_bottom_background_highlighted"] forState:UIControlStateHighlighted];
// 取消高亮图片调整效果
[button setAdjustsImageWhenHighlighted:NO]; // 加入到view中
[self addSubview:button];
[self.buttons addObject:button]; return button;
} // 设置分割线
- (void) setupDivides {
for (int i=; i<self.buttons.count; i++) {
UIImageView *divide = [[UIImageView alloc] init];
divide.image = [UIImage imageWithNamed:@"timeline_card_bottom_line"];
divide.contentMode = UIViewContentModeCenter; [self addSubview:divide];
[self.divides addObject:divide];
}
} /** 设置Frame模型 */
- (void)setToolbarFrame:(HVWStatusToolbarFrame *)toolbarFrame {
_toolbarFrame = toolbarFrame; // 设置自己的frame
self.frame = toolbarFrame.frame; // 配置toolbar按钮数据
[self setupToolBarButton];
} // 设置子控件frame
- (void)layoutSubviews {
[super layoutSubviews]; // 配置按钮frame
CGFloat buttonWidth = self.width / self.buttons.count;
CGFloat buttonHeight = self.height;
CGFloat buttonY = ;
for (int i=; i<self.buttons.count; i++) {
CGFloat buttonX = i * buttonWidth;
UIButton *button = self.buttons[i]; button.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
} // 配置分割线frame
CGFloat divideWidth = ;
CGFloat divideHeight = self.height;
for (int i=; i<self.divides.count; i++) {
CGFloat divideX = (i + ) * buttonWidth;
UIImageView *imageView = self.divides[i];
imageView.size = CGSizeMake(divideWidth, divideHeight);
imageView.center = CGPointMake(divideX, self.height * 0.5);
}
} /** 设置toolbar按钮数据 */
- (void) setupToolBarButton {
HVWStatus *status = self.toolbarFrame.status; // 评论
[self setupButtonTitle:self.commentButton withOriginalTitle:@"评论" titleCount:status.comments_count]; // 转发
[self setupButtonTitle:self.repostButton withOriginalTitle:@"转发" titleCount:status.reposts_count]; // 点赞
[self setupButtonTitle:self.attitudeButton withOriginalTitle:@"赞" titleCount:status.attitudes_count];
} /** 设置按钮标题 */
- (void) setupButtonTitle:(UIButton *) button withOriginalTitle:(NSString *)buttonTitle titleCount:(int)titleCount {
// 当数量超过1万的时候,使用“万”作为单位
if (titleCount >= ) {
buttonTitle = [NSString stringWithFormat:@"%.1f万", (titleCount / 10000.0)];
buttonTitle = [buttonTitle stringByReplacingOccurrencesOfString:@".0" withString:@""]; // 去除".0"小数
} else if (titleCount) {
buttonTitle = [NSString stringWithFormat:@"%d", titleCount];
} [button setTitle:buttonTitle forState:UIControlStateNormal];
} @end
 

[iOS微博项目 - 4.5] - 每条微博的底部工具条的更多相关文章

  1. [iOS微博项目 - 3.0] - 手动刷新微博

    github: https://github.com/hellovoidworld/HVWWeibo   A.下拉刷新微博 1.需求 在“首页”界面,下拉到一定距离的时候刷新微博数据 刷新数据的时候使 ...

  2. [iOS微博项目 - 4.2] - 设置转发微博背景

    github: https://github.com/hellovoidworld/HVWWeibo A.转发微博部分的淡灰色背景 1.需求 转发微博部分需要设置背景色 使用图片作为背景   2.思路 ...

  3. [iOS微博项目 - 4.1] - cell的frame模型

    github: https://github.com/hellovoidworld/HVWWeibo A.cell的frame模型设计 1.需求 每个cell都有一个frame实例引用 frame模型 ...

  4. [ExtJS5学习笔记]第八节 Extjs5的Ext.toolbar.Toolbar工具条组件及其应用

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/38515499 本文作者:sushengmiyan ------------------ ...

  5. 黄聪:自定义WordPress前台、后台顶部菜单栏管理工具条的技巧

    使用WordPress开发网站项目,很多时候都需要对进行后台定制,今天倡萌主要分享下自定义顶部管理工具条的使用技巧. 注:如无特殊说明,请将下面的代码添加到主题的 functions.php  或者插 ...

  6. 黄聪:自定义WordPress顶部管理工具条的技巧(转)

    使用WordPress开发网站项目,很多时候都需要对进行后台定制,今天倡萌主要分享下自定义顶部管理工具条的使用技巧. 注:如无特殊说明,请将下面的代码添加到主题的 functions.php  或者插 ...

  7. 积累的VC编程小技巧之工具条和状态条

    1.工具条和状态条中控件的添加: 方法⑴.只能在ToolBar里创建控件:首先,在ToolBar中创建一个Button,其ID为ID_TOOL_COMBO(我们要将创建的控件放在该Button的位置上 ...

  8. SWIFT显示底部的工具条

    有以下页面显示我的讯息,用户可以点击右上角的编辑按钮进入删除状态.点击编辑按钮后,按钮文字改为“取消”,左上角的按钮变为“全选”,同时显示底部工具条带有“删除”按钮 实现起来挺简单的,在正常状态下点击 ...

  9. iOS开发小技巧--微博项目中的键盘工具条

    微博项目中的键盘工具条 项目中的键盘工具条不能使用inputAccessoryView,因为inputAccessoryView不能实现键盘隐藏的时候,工具条还显示在眼前,如图: 所以,果断决定将工具 ...

随机推荐

  1. Git Manual / Git使用手册 / Git, GitLab, Git Bash, TortoiseGit (建议全文复制到Word文档中通过导航窗格查看)

    Git使用手册 目录 1     引言 2     Git.GitLab简介 2.1      Git 2.2      GitLab 2.3      Git基本概念 3     运行环境 4    ...

  2. tomcat开启https协议

    1.在tomcat的conf/server.xml 中配置 <Connector port="443" protocol="org.apache.coyote.ht ...

  3. FreeRtos——多任务

    官方资料整理测试: 多任务和单任务几乎没有差别.只用多创建一个或多个任务,其他地方和单任务时相同. static void AppTaskCreate(void) { xTaskCreate(vTas ...

  4. 逃生dp

    蒜头君在玩一款逃生的游戏.在一个 n \times mn×m的矩形地图上,蒜头位于其中一个点.地图上每个格子有加血的药剂,和掉血的火焰,药剂的药效不同,火焰的大小也不同,每个格子上有一个数字,如果格子 ...

  5. java 错误汇总

    一.怎么处理警告:编码 GBK 的不可映射字符 解决办法是:应该使用-encoding参数指明编码方式:javac -encoding UTF-8 XX.java,这下没警告了,运行也正确了在JCre ...

  6. IOS微信API异常:unrecognized selector sent to instance 0x17005c9b0'

    开发IOS整合微信API的时候,在运行程序的过程中可能会在注册你的APPID的时候抛出此异常而导致程序崩溃. 异常描述 [7661:2826851] *** Terminating app due t ...

  7. 关于JQueryMobile中Slider的一点研究

    滑动条 Slider                 给input的设置一个新的HTML5属性为type="range",可以给页面添加滑动条组件,可以指定它的value值(当前值 ...

  8. 应用于Java中的一个开源的表达式语言(Expression Language)

    OGNL(英文全称:Object Graph Navigation Language,中文名:对象导航图语言)是应用于Java中的一个开源的表达式语言(Expression Language),它被集 ...

  9. 我们把Mybatis的功能架构分为三层:

    我们把Mybatis的功能架构分为三层: (1)API接口层:提供给外部使用的接口API,开发人员通过这些本地API来操纵数据库.接口层一接收到调用请求就会调用数据处理层来完成具体的数据处理. (2) ...

  10. UML概述

    UML (Unified Modeling Language)统一建模语言,是描述.构造和文档化系统制品的可视化语言,是一种图形表示法. UML用途:UML是一种工具,主要用在我们对软件用面向对象的方 ...