WBStatusLayout.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //
  2. // WBFeedLayout.h
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 15/9/5.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "YYKit.h"
  9. #import "WBModel.h"
  10. #import "WBStatusHelper.h"
  11. // 宽高
  12. #define kWBCellTopMargin 8 // cell 顶部灰色留白
  13. #define kWBCellTitleHeight 36 // cell 标题高度 (例如"仅自己可见")
  14. #define kWBCellPadding 12 // cell 内边距
  15. #define kWBCellPaddingText 10 // cell 文本与其他元素间留白
  16. #define kWBCellPaddingPic 4 // cell 多张图片中间留白
  17. #define kWBCellProfileHeight 56 // cell 名片高度
  18. #define kWBCellCardHeight 70 // cell card 视图高度
  19. #define kWBCellNamePaddingLeft 14 // cell 名字和 avatar 之间留白
  20. #define kWBCellContentWidth (kScreenWidth - 2 * kWBCellPadding) // cell 内容宽度
  21. #define kWBCellNameWidth (kScreenWidth - 110) // cell 名字最宽限制
  22. #define kWBCellTagPadding 8 // tag 上下留白
  23. #define kWBCellTagNormalHeight 16 // 一般 tag 高度
  24. #define kWBCellTagPlaceHeight 24 // 地理位置 tag 高度
  25. #define kWBCellToolbarHeight 35 // cell 下方工具栏高度
  26. #define kWBCellToolbarBottomMargin 2 // cell 下方灰色留白
  27. // 字体 应该做成动态的,这里只是 Demo,临时写死了。
  28. #define kWBCellNameFontSize 16 // 名字字体大小
  29. #define kWBCellSourceFontSize 12 // 来源字体大小
  30. #define kWBCellTextFontSize 17 // 文本字体大小
  31. #define kWBCellTextFontRetweetSize 16 // 转发字体大小
  32. #define kWBCellCardTitleFontSize 16 // 卡片标题文本字体大小
  33. #define kWBCellCardDescFontSize 12 // 卡片描述文本字体大小
  34. #define kWBCellTitlebarFontSize 14 // 标题栏字体大小
  35. #define kWBCellToolbarFontSize 14 // 工具栏字体大小
  36. // 颜色
  37. #define kWBCellNameNormalColor UIColorHex(333333) // 名字颜色
  38. #define kWBCellNameOrangeColor UIColorHex(f26220) // 橙名颜色 (VIP)
  39. #define kWBCellTimeNormalColor UIColorHex(828282) // 时间颜色
  40. #define kWBCellTimeOrangeColor UIColorHex(f28824) // 橙色时间 (最新刷出)
  41. #define kWBCellTextNormalColor UIColorHex(333333) // 一般文本色
  42. #define kWBCellTextSubTitleColor UIColorHex(5d5d5d) // 次要文本色
  43. #define kWBCellTextHighlightColor UIColorHex(527ead) // Link 文本色
  44. #define kWBCellTextHighlightBackgroundColor UIColorHex(bfdffe) // Link 点击背景色
  45. #define kWBCellToolbarTitleColor UIColorHex(929292) // 工具栏文本色
  46. #define kWBCellToolbarTitleHighlightColor UIColorHex(df422d) // 工具栏文本高亮色
  47. #define kWBCellBackgroundColor UIColorHex(f2f2f2) // Cell背景灰色
  48. #define kWBCellHighlightColor UIColorHex(f0f0f0) // Cell高亮时灰色
  49. #define kWBCellInnerViewColor UIColorHex(f7f7f7) // Cell内部卡片灰色
  50. #define kWBCellInnerViewHighlightColor UIColorHex(f0f0f0) // Cell内部卡片高亮时灰色
  51. #define kWBCellLineColor [UIColor colorWithWhite:0.000 alpha:0.09] //线条颜色
  52. #define kWBLinkHrefName @"href" //NSString
  53. #define kWBLinkURLName @"url" //WBURL
  54. #define kWBLinkTagName @"tag" //WBTag
  55. #define kWBLinkTopicName @"topic" //WBTopic
  56. #define kWBLinkAtName @"at" //NSString
  57. /// 风格
  58. typedef NS_ENUM(NSUInteger, WBLayoutStyle) {
  59. WBLayoutStyleTimeline = 0, ///< 时间线 (目前只支持这一种)
  60. WBLayoutStyleDetail, ///< 详情页
  61. };
  62. /// 卡片类型 (这里随便写的,只适配了微博中常见的类型)
  63. typedef NS_ENUM(NSUInteger, WBStatusCardType) {
  64. WBStatusCardTypeNone = 0, ///< 没卡片
  65. WBStatusCardTypeNormal, ///< 一般卡片布局
  66. WBStatusCardTypeVideo, ///< 视频
  67. };
  68. /// 最下方Tag类型,也是随便写的,微博可能有更多类型同时存在等情况
  69. typedef NS_ENUM(NSUInteger, WBStatusTagType) {
  70. WBStatusTagTypeNone = 0, ///< 没Tag
  71. WBStatusTagTypeNormal, ///< 文本
  72. WBStatusTagTypePlace, ///< 地点
  73. };
  74. /**
  75. 一个 Cell 的布局。
  76. 布局排版应该在后台线程完成。
  77. */
  78. @interface WBStatusLayout : NSObject
  79. - (instancetype)initWithStatus:(WBStatus *)status style:(WBLayoutStyle)style;
  80. - (void)layout; ///< 计算布局
  81. - (void)updateDate; ///< 更新时间字符串
  82. // 以下是数据
  83. @property (nonatomic, strong) WBStatus *status;
  84. @property (nonatomic, assign) WBLayoutStyle style;
  85. //以下是布局结果
  86. // 顶部留白
  87. @property (nonatomic, assign) CGFloat marginTop; //顶部灰色留白
  88. // 标题栏
  89. @property (nonatomic, assign) CGFloat titleHeight; //标题栏高度,0为没标题栏
  90. @property (nonatomic, strong) YYTextLayout *titleTextLayout; // 标题栏
  91. // 个人资料
  92. @property (nonatomic, assign) CGFloat profileHeight; //个人资料高度(包括留白)
  93. @property (nonatomic, strong) YYTextLayout *nameTextLayout; // 名字
  94. @property (nonatomic, strong) YYTextLayout *sourceTextLayout; //时间/来源
  95. // 文本
  96. @property (nonatomic, assign) CGFloat textHeight; //文本高度(包括下方留白)
  97. @property (nonatomic, strong) YYTextLayout *textLayout; //文本
  98. // 图片
  99. @property (nonatomic, assign) CGFloat picHeight; //图片高度,0为没图片
  100. @property (nonatomic, assign) CGSize picSize;
  101. // 转发
  102. @property (nonatomic, assign) CGFloat retweetHeight; //转发高度,0为没转发
  103. @property (nonatomic, assign) CGFloat retweetTextHeight;
  104. @property (nonatomic, strong) YYTextLayout *retweetTextLayout; //被转发文本
  105. @property (nonatomic, assign) CGFloat retweetPicHeight;
  106. @property (nonatomic, assign) CGSize retweetPicSize;
  107. @property (nonatomic, assign) CGFloat retweetCardHeight;
  108. @property (nonatomic, assign) WBStatusCardType retweetCardType;
  109. @property (nonatomic, strong) YYTextLayout *retweetCardTextLayout; //被转发文本
  110. @property (nonatomic, assign) CGRect retweetCardTextRect;
  111. // 卡片
  112. @property (nonatomic, assign) CGFloat cardHeight; //卡片高度,0为没卡片
  113. @property (nonatomic, assign) WBStatusCardType cardType;
  114. @property (nonatomic, strong) YYTextLayout *cardTextLayout; //卡片文本
  115. @property (nonatomic, assign) CGRect cardTextRect;
  116. // Tag
  117. @property (nonatomic, assign) CGFloat tagHeight; //Tip高度,0为没tip
  118. @property (nonatomic, assign) WBStatusTagType tagType;
  119. @property (nonatomic, strong) YYTextLayout *tagTextLayout; //最下方tag
  120. // 工具栏
  121. @property (nonatomic, assign) CGFloat toolbarHeight; // 工具栏
  122. @property (nonatomic, strong) YYTextLayout *toolbarRepostTextLayout;
  123. @property (nonatomic, strong) YYTextLayout *toolbarCommentTextLayout;
  124. @property (nonatomic, strong) YYTextLayout *toolbarLikeTextLayout;
  125. @property (nonatomic, assign) CGFloat toolbarRepostTextWidth;
  126. @property (nonatomic, assign) CGFloat toolbarCommentTextWidth;
  127. @property (nonatomic, assign) CGFloat toolbarLikeTextWidth;
  128. // 下边留白
  129. @property (nonatomic, assign) CGFloat marginBottom; //下边留白
  130. // 总高度
  131. @property (nonatomic, assign) CGFloat height;
  132. /*
  133. 用户信息 status.user
  134. 文本 status.text
  135. 图片 status.pics
  136. 转发 status.retweetedStatus
  137. 文本 status.retweetedStatus.user + status.retweetedStatus.text
  138. 图片 status.retweetedStatus.pics
  139. 卡片 status.retweetedStatus.pageInfo
  140. 卡片 status.pageInfo
  141. Tip status.tagStruct
  142. 1.根据 urlStruct 中每个 URL.shortURL 来匹配文本,将其替换为图标+友好描述
  143. 2.根据 topicStruct 中每个 Topic.topicTitle 来匹配文本,标记为话题
  144. 2.匹配 @用户名
  145. 4.匹配 [表情]
  146. 一条里,图片|转发|卡片不能同时存在,优先级是 转发->图片->卡片
  147. 如果不是转发,则显示Tip
  148. 文本
  149. 文本 图片/卡片
  150. 文本 Tip
  151. 文本 图片/卡片 Tip
  152. 文本 转发[文本] /Tip
  153. 文本 转发[文本 图片] /Tip
  154. 文本 转发[文本 卡片] /Tip
  155. 话题 #爸爸去哪儿#
  156. 电影 timeline_card_small_movie #冰雪奇缘[电影]#
  157. 图书 timeline_card_small_book #纸牌屋[图书]#
  158. 音乐 timeline_card_small_music #Let It Go[音乐]#
  159. 地点 timeline_card_small_location #理想国际大厦[地点]#
  160. 股票 timeline_icon_stock #腾讯控股 kh00700[股票]#
  161. */
  162. @end
  163. /**
  164. 文本 Line 位置修改
  165. 将每行文本的高度和位置固定下来,不受中英文/Emoji字体的 ascent/descent 影响
  166. */
  167. @interface WBTextLinePositionModifier : NSObject <YYTextLinePositionModifier>
  168. @property (nonatomic, strong) UIFont *font; // 基准字体 (例如 Heiti SC/PingFang SC)
  169. @property (nonatomic, assign) CGFloat paddingTop; //文本顶部留白
  170. @property (nonatomic, assign) CGFloat paddingBottom; //文本底部留白
  171. @property (nonatomic, assign) CGFloat lineHeightMultiple; //行距倍数
  172. - (CGFloat)heightForLineCount:(NSUInteger)lineCount;
  173. @end