A.每条微博的底部工具条
1.需求
  • 每条微博底部都有一个工具条
  • 显示3个按钮:评论、转发、赞
  • 按钮间用分割线隔开
  • 有评论数、转发数、赞数的时候显示相应数据,没有则显示文本
 
 
2.思路
(略)
 
3.实现
 
(1)微博数据模型中已经带有了相应数据字段
  1. // HVWStatus.h
  2. /** int 转发数 */
  3. @property(nonatomic, assign) int reposts_count;
  4.  
  5. /** int 评论数 */
  6. @property(nonatomic, assign) int comments_count;
  7.  
  8. /** int 表态数 */
  9. @property(nonatomic, assign) int attitudes_count;
 
(2)直接在toolbar view中,在设置status数据的时候处理
  1. //
  2. // HVWStatusToolbar.m
  3. // HVWWeibo
  4. //
  5. // Created by hellovoidworld on 15/2/12.
  6. // Copyright (c) 2015年 hellovoidworld. All rights reserved.
  7. //
  8.  
  9. #import "HVWStatusToolbar.h"
  10.  
  11. @interface HVWStatusToolbar()
  12.  
  13. /** 按钮数组 */
  14. @property(nonatomic, strong) NSMutableArray *buttons;
  15.  
  16. /** 分割线数组 */
  17. @property(nonatomic, strong) NSMutableArray *divides;
  18.  
  19. /** 转发按钮 */
  20. @property(nonatomic, strong) UIButton *repostButton;
  21.  
  22. /** 评论按钮 */
  23. @property(nonatomic, strong) UIButton *commentButton;
  24.  
  25. /** 点赞按钮 */
  26. @property(nonatomic, strong) UIButton *attitudeButton;
  27.  
  28. @end
  29.  
  30. @implementation HVWStatusToolbar
  31.  
  32. - (NSMutableArray *)buttons {
  33. if (nil == _buttons) {
  34. _buttons = [NSMutableArray array];
  35. }
  36. return _buttons;
  37. }
  38.  
  39. - (NSMutableArray *)divides {
  40. if (nil == _divides) {
  41. _divides = [NSMutableArray array];
  42. }
  43. return _divides;
  44. }
  45.  
  46. /** 代码自定义初始化方法 */
  47. - (instancetype)initWithFrame:(CGRect)frame {
  48. self = [super initWithFrame:frame];
  49.  
  50. if (self) {
  51. // 设置toolbar背景
  52. self.image = [UIImage resizedImage:@"timeline_card_bottom_background"];
  53.  
  54. // 为了按钮能够点击,设置父控件可交互
  55. self.userInteractionEnabled = YES;
  56.  
  57. // 添加按钮
  58. self.commentButton = [self setupButtonWithIcon:@"timeline_icon_comment" title:@"评论"];
  59. self.repostButton = [self setupButtonWithIcon:@"timeline_icon_retweet" title:@"转发"];
  60. self.attitudeButton = [self setupButtonWithIcon:@"timeline_icon_unlike" title:@"赞"];
  61.  
  62. // 添加分割线
  63. [self setupDivides];
  64. }
  65.  
  66. return self;
  67. }
  68.  
  69. // 设置按钮
  70. - (UIButton *) setupButtonWithIcon:(NSString *)icon title:(NSString *)title {
  71. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  72. // 标题
  73. [button setTitle:title forState:UIControlStateNormal];
  74. // 图片
  75. [button setImage:[UIImage imageWithNamed:icon] forState:UIControlStateNormal];
  76. // 字体颜色
  77. [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  78. // 字体大小
  79. button.titleLabel.font = [UIFont systemFontOfSize:];
  80. // 图标、文本之间间隙
  81. [button setTitleEdgeInsets:UIEdgeInsetsMake(, , , )];
  82. // 高亮背景
  83. [button setBackgroundImage:[UIImage imageWithNamed:@"timeline_card_bottom_background_highlighted"] forState:UIControlStateHighlighted];
  84. // 取消高亮图片调整效果
  85. [button setAdjustsImageWhenHighlighted:NO];
  86.  
  87. // 加入到view中
  88. [self addSubview:button];
  89. [self.buttons addObject:button];
  90.  
  91. return button;
  92. }
  93.  
  94. // 设置分割线
  95. - (void) setupDivides {
  96. for (int i=; i<self.buttons.count; i++) {
  97. UIImageView *divide = [[UIImageView alloc] init];
  98. divide.image = [UIImage imageWithNamed:@"timeline_card_bottom_line"];
  99. divide.contentMode = UIViewContentModeCenter;
  100.  
  101. [self addSubview:divide];
  102. [self.divides addObject:divide];
  103. }
  104. }
  105.  
  106. /** 设置Frame模型 */
  107. - (void)setToolbarFrame:(HVWStatusToolbarFrame *)toolbarFrame {
  108. _toolbarFrame = toolbarFrame;
  109.  
  110. // 设置自己的frame
  111. self.frame = toolbarFrame.frame;
  112.  
  113. // 配置toolbar按钮数据
  114. [self setupToolBarButton];
  115. }
  116.  
  117. // 设置子控件frame
  118. - (void)layoutSubviews {
  119. [super layoutSubviews];
  120.  
  121. // 配置按钮frame
  122. CGFloat buttonWidth = self.width / self.buttons.count;
  123. CGFloat buttonHeight = self.height;
  124. CGFloat buttonY = ;
  125. for (int i=; i<self.buttons.count; i++) {
  126. CGFloat buttonX = i * buttonWidth;
  127. UIButton *button = self.buttons[i];
  128.  
  129. button.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
  130. }
  131.  
  132. // 配置分割线frame
  133. CGFloat divideWidth = ;
  134. CGFloat divideHeight = self.height;
  135. for (int i=; i<self.divides.count; i++) {
  136. CGFloat divideX = (i + ) * buttonWidth;
  137. UIImageView *imageView = self.divides[i];
  138. imageView.size = CGSizeMake(divideWidth, divideHeight);
  139. imageView.center = CGPointMake(divideX, self.height * 0.5);
  140. }
  141. }
  142.  
  143. /** 设置toolbar按钮数据 */
  144. - (void) setupToolBarButton {
  145. HVWStatus *status = self.toolbarFrame.status;
  146.  
  147. // 评论
  148. [self setupButtonTitle:self.commentButton withOriginalTitle:@"评论" titleCount:status.comments_count];
  149.  
  150. // 转发
  151. [self setupButtonTitle:self.repostButton withOriginalTitle:@"转发" titleCount:status.reposts_count];
  152.  
  153. // 点赞
  154. [self setupButtonTitle:self.attitudeButton withOriginalTitle:@"赞" titleCount:status.attitudes_count];
  155. }
  156.  
  157. /** 设置按钮标题 */
  158. - (void) setupButtonTitle:(UIButton *) button withOriginalTitle:(NSString *)buttonTitle titleCount:(int)titleCount {
  159. // 当数量超过1万的时候,使用“万”作为单位
  160. if (titleCount >= ) {
  161. buttonTitle = [NSString stringWithFormat:@"%.1f万", (titleCount / 10000.0)];
  162. buttonTitle = [buttonTitle stringByReplacingOccurrencesOfString:@".0" withString:@""]; // 去除".0"小数
  163. } else if (titleCount) {
  164. buttonTitle = [NSString stringWithFormat:@"%d", titleCount];
  165. }
  166.  
  167. [button setTitle:buttonTitle forState:UIControlStateNormal];
  168. }
  169.  
  170. @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. UISCREEN 和支持高分辨率的显示屏

    UIScreen对象包含了整个屏幕的边界矩形.当构造应用的用户界面接口时,你应该使用该对象的属性来获得推荐的矩形大小,用以构造你的程序窗口. CGRect bound = [[UIScreen mai ...

  2. vue 和ng的区别

    vue:    读音:    v-u-e    view vue到底是什么?        一个mvvm框架(库).和angular类似        比较容易上手.小巧    mvc:       ...

  3. Hystrix的用法demo

    1.引入依赖 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId> ...

  4. 用C语言(apue)实现 把时间戳转换为国标格式的字符串(2017-07-17 22:36:12)的函数

    /*******************************************************************************/ /** *** 函 数 名: cha ...

  5. 【转】在MAC下配置MySQL 5.7 数据库的编码问题

    1.MySQL 5.7 for MAC 默认没有my.cnf文件 ,首先 新建my.cnf文件: 2.在my.cnf文件追加 1 2 3 4 5 6 7 8 [mysqld] character-se ...

  6. PowerPoint 2010 设置演讲者模式

  7. 一款基于jQuery的图片左右滑动焦点图

    今天给大家分享一款基于jQuery的焦点图插件,这款jQuery焦点图插件的特点是可以多张图片左右滑动切换,可以点击切换按钮进行图片滑动,同时也支持图片自动切换.另外,这款jQuery焦点图是宽屏的, ...

  8. springJDBC实现查询

    其实在Spring这个框架中,提供了一些对JDBC访问数据库的封装,其中JdbcTemplate就是一个很好用的类,下面来 演示一下这个类的一些用法.首先需要导入commons-logging.jar ...

  9. UCOS2_STM32移植详细过程(汇总)

    Ⅰ.概述 笔者发现一个问题,很多初学者,甚至很多工作一两年的人,他们有一种依赖的思想,就是希望从别处获取的软件代码不做任何修改,直接可以运行或者使用.笔者想说,实践才是检验真理的关键,实践才是掌握知识 ...

  10. CentOS下yum安装PostgreSQL

    关键词:centos install PostgreSQL Configure YUM repository vim /etc/yum.repos.d/CentOS-Base.repo [base] ...