YHWorkGroup.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // YHWorkGroup.m
  3. // github: https://github.com/samuelandkevin
  4. // CSDN: http://blog.csdn.net/samuelandkevin
  5. // Created by samuelandkevin on 16/5/5.
  6. // Copyright © 2016年 HKP. All rights reserved.
  7. //
  8. #import "YHWorkGroup.h"
  9. #import <UIKit/UIKit.h>
  10. extern const CGFloat contentLabelFontSize;
  11. extern CGFloat maxContentLabelHeight;
  12. extern CGFloat maxContentRepostLabelHeight;
  13. extern const CGFloat kMarginContentLeft;
  14. extern const CGFloat kMarginContentRight;
  15. @implementation YHWorkGroup
  16. {
  17. CGFloat _lastContentWidth;
  18. }
  19. @synthesize msgContent = _msgContent;
  20. - (void)setMsgContent:(NSString *)msgContent
  21. {
  22. _msgContent = msgContent;
  23. }
  24. - (NSString *)msgContent
  25. {
  26. CGFloat contentW = kScreenW - kMarginContentLeft - kMarginContentRight ;
  27. if (contentW != _lastContentWidth) {
  28. _lastContentWidth = contentW;
  29. CGRect textRect = [_msgContent boundingRectWithSize:CGSizeMake(contentW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:contentLabelFontSize]} context:nil];
  30. if (!_isRepost)
  31. {
  32. if (textRect.size.height > maxContentLabelHeight+contentLabelFontSize) {
  33. _shouldShowMoreButton = YES;
  34. } else {
  35. _shouldShowMoreButton = NO;
  36. }
  37. }
  38. else{
  39. if (textRect.size.height > maxContentRepostLabelHeight+contentLabelFontSize)
  40. {
  41. _shouldShowMoreButton = YES;
  42. } else {
  43. _shouldShowMoreButton = NO;
  44. }
  45. }
  46. }
  47. return _msgContent;
  48. }
  49. - (void)setIsOpening:(BOOL)isOpening
  50. {
  51. if (!_shouldShowMoreButton) {
  52. _isOpening = NO;
  53. } else {
  54. _isOpening = isOpening;
  55. }
  56. }
  57. @end