MHTopicFrame.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // MHTopicFrame.m
  3. // MHDevelopExample
  4. //
  5. // Created by CoderMikeHe on 17/2/8.
  6. // Copyright © 2017年 CoderMikeHe. All rights reserved.
  7. //
  8. #import "MHTopicFrame.h"
  9. @interface MHTopicFrame ()
  10. /** 头像frame */
  11. @property (nonatomic , assign) CGRect avatarFrame;
  12. /** 昵称frame */
  13. @property (nonatomic , assign) CGRect nicknameFrame;
  14. /** star*/
  15. @property (nonatomic , assign) CGRect starFrame;
  16. /** 点赞frame */
  17. @property (nonatomic , assign) CGRect thumbFrame;
  18. /** 更多frame */
  19. @property (nonatomic , assign) CGRect moreFrame;
  20. /** 时间frame */
  21. @property (nonatomic , assign) CGRect createTimeFrame;
  22. /** 话题内容frame */
  23. @property (nonatomic , assign) CGRect textFrame;
  24. /** height*/
  25. @property (nonatomic , assign) CGFloat height;
  26. /** tableViewFrame cell嵌套tableView用到 本人有点懒 ,公用了一套模型 */
  27. @property (nonatomic , assign ) CGRect tableViewFrame;
  28. @end
  29. @implementation MHTopicFrame
  30. - (instancetype)init
  31. {
  32. self = [super init];
  33. if (self) {
  34. // 初始化
  35. _commentFrames = [NSMutableArray array];
  36. }
  37. return self;
  38. }
  39. #pragma mark - Setter
  40. - (void)setTopic:(MHTopic *)topic
  41. {
  42. _topic = topic;
  43. // 整个宽度
  44. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  45. // 头像
  46. CGFloat avatarX = MHTopicHorizontalSpace;
  47. CGFloat avatarY = MHTopicVerticalSpace;
  48. CGFloat avatarW = MHTopicAvatarWH;
  49. CGFloat avatarH = MHTopicAvatarWH;
  50. self.avatarFrame = (CGRect){{avatarX , avatarY},{avatarW , avatarH}};
  51. // 布局点赞按钮
  52. CGFloat moreW = MHTopicMoreButtonW;
  53. CGFloat moreX = width - moreW - 21;
  54. CGFloat moreY = 25.5f;
  55. CGFloat moreH = 14.5f;
  56. self.thumbFrame = CGRectMake(moreX, moreY, moreW, moreH);
  57. // 布局点赞按钮
  58. // CGFloat thumbW = 44;
  59. // CGFloat thumbX = CGRectGetMinX(self.moreFrame) - thumbW;
  60. // CGFloat thumbY = avatarY;
  61. // CGFloat thumbH = moreH;
  62. // self.thumbFrame = CGRectMake(thumbX, thumbY, thumbW, thumbH);
  63. UILabel * label = [UILabel new];
  64. label.font = Kfont(17);
  65. label.text = topic.Name;
  66. // 昵称
  67. CGFloat nicknameX = CGRectGetMaxX(self.avatarFrame) + 12.f;
  68. CGFloat nicknameY = avatarY;
  69. CGSize textLimitSize = CGSizeMake(width - nicknameX - 15, MAXFLOAT);
  70. CGFloat nicknameW = [label sizeThatFits:textLimitSize].width;
  71. if (nicknameW > 100) {
  72. nicknameW = 100;
  73. }
  74. CGFloat nicknameH = 20.f;
  75. self.nicknameFrame = CGRectMake(nicknameX, nicknameY, nicknameW, nicknameH);
  76. CGFloat starX = CGRectGetMaxX(self.nicknameFrame) + 12.f;
  77. CGFloat starY = nicknameY + 5;
  78. CGFloat starW = 58;
  79. CGFloat starH = 10.f;
  80. self.starFrame = CGRectMake(starX, starY, starW, starH);
  81. // 时间
  82. CGFloat createX = nicknameX;
  83. CGFloat createY = CGRectGetMaxY(self.avatarFrame) - 10;
  84. CGFloat createW = width - createX;
  85. CGFloat createH = 16;
  86. self.createTimeFrame = CGRectMake(createX, createY, createW, createH);
  87. // 内容
  88. CGFloat textX = nicknameX;
  89. // CGSize textLimitSize = CGSizeMake(width - textX - 15, MAXFLOAT);
  90. CGFloat textY = CGRectGetMaxY(self.createTimeFrame);
  91. CGFloat textH = [YYTextLayout layoutWithContainerSize:textLimitSize text:topic.attributedText].textBoundingSize.height + 25;
  92. self.textFrame = (CGRect){{textX , textY} , {textLimitSize.width, textH}};
  93. CGFloat tableViewX = textX;
  94. CGFloat tableViewY = CGRectGetMaxY(self.textFrame);
  95. CGFloat tableViewW = textLimitSize.width;
  96. CGFloat tableViewH = 0;
  97. // 评论数据
  98. if (topic.CommentReplyResults>0)
  99. {
  100. for (MHComment *comment in topic.CommentReplyResults)
  101. {
  102. MHCommentFrame *commentFrame = [[MHCommentFrame alloc] init];
  103. commentFrame.maxW = textLimitSize.width;
  104. commentFrame.comment = comment;
  105. [self.commentFrames addObject:commentFrame];
  106. tableViewH += commentFrame.cellHeight;
  107. }
  108. }
  109. self.tableViewFrame = CGRectMake(tableViewX, tableViewY, tableViewW, tableViewH);
  110. // 自身高度
  111. self.height = CGRectGetMaxY(self.textFrame);
  112. }
  113. @end