MHTopicFrame.m 3.6 KB

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