CommentSetView.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // CommentSetView.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/26.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "CommentSetView.h"
  9. @interface CommentSetView ()
  10. @property (nonatomic, strong) TDButton *commentButton;
  11. @end
  12. @implementation CommentSetView
  13. - (instancetype)initWithFrame:(CGRect)frame
  14. {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. self.backgroundColor = [UIColor whiteColor];
  18. // [self addSubview:self.lineView];
  19. [self addSubview:self.commentButton];
  20. [self addSubview:self.thumbButton];
  21. [self addSubview:self.collectButton];
  22. [self addSubview:self.sharedButton];
  23. CGFloat height = frame.size.height;
  24. CGFloat rightMargin = 15.f;
  25. _sharedButton.frame = CGRectMake(kGXScreenWidth - rightMargin - 18.f, (height-18.f)/2.0, 18.f, 18.f);
  26. rightMargin += 18.f + 25.f;
  27. _collectButton.frame = CGRectMake(kGXScreenWidth - rightMargin - 18.f, (height-18.f)/2.0, 18.f, 18.f);
  28. rightMargin += 18.f + 25.f;
  29. _thumbButton.frame = CGRectMake(kGXScreenWidth - rightMargin - 18.f, (height-18.f)/2.0, 18.f, 18.f);
  30. rightMargin += 18.f + 34.f;
  31. _commentButton.frame = CGRectMake(15.f, 7, kGXScreenWidth - rightMargin - 15, 45-7-7);
  32. UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,0,kGXScreenWidth, 0.5f)];
  33. lineView.backgroundColor = UIColorHex(E5E5E5);
  34. [self addSubview:lineView];
  35. UILabel *numLabel = [[UILabel alloc]init];
  36. numLabel.textColor = UIColorHex(999999);
  37. numLabel.text = @"0人";
  38. numLabel.numberOfLines = 0;
  39. numLabel.font = [UIFont systemFontOfSize:8.f];
  40. //[ZYCTool setLabel:numLabel withSpace:0 withFont:[UIFont systemFontOfSize:8.f] setLineSpace:0 setTextSpace:0.f];
  41. CGSize numberSize = [numLabel sizeThatFits:CGSizeMake(41, 31)];
  42. numLabel.frame = CGRectMake(kGXScreenWidth - rightMargin - numberSize.width-5 ,11,numberSize.width, numberSize.height);
  43. [self addSubview:numLabel];
  44. self.numLabel = numLabel;
  45. self.numLabel.textAlignment = NSTextAlignmentCenter;
  46. UILabel *numLabelb = [[UILabel alloc]init];
  47. numLabelb.textColor = UIColorHex(999999);
  48. numLabelb.text = @"评 论";
  49. numLabelb.textAlignment = NSTextAlignmentCenter;
  50. numLabelb.numberOfLines = 0;
  51. numLabelb.font = [UIFont systemFontOfSize:7];
  52. numLabelb.frame = CGRectMake(kGXScreenWidth - rightMargin - numberSize.width - 10 ,6 + 9 + numberSize.height,numberSize.width + 10, numberSize.height);
  53. [self addSubview:numLabelb];
  54. UIView *verticalView = [[UIView alloc]initWithFrame:CGRectMake(kGXScreenWidth - rightMargin - numberSize.width - 10,9,0.5, 45-7-7-4)];
  55. verticalView.backgroundColor = UIColorHex(#CCCCCC) ;
  56. [self addSubview:verticalView];
  57. self.commentNumberBtn = [TDButton new];
  58. [self.commentNumberBtn addTarget:self action:@selector(commentNunberClick) forControlEvents:UIControlEventTouchUpInside];
  59. self.commentNumberBtn.frame = CGRectMake(kGXScreenWidth - rightMargin - numberSize.width - 5, 0, numberSize.width + 10, self.height);
  60. [self addSubview:self.commentNumberBtn];
  61. [_collectButton setButtonBadge:0];
  62. [_thumbButton setButtonBadge:0];
  63. [_sharedButton setButtonBadge:0];
  64. }
  65. return self;
  66. }
  67. - (void)commentNunberClick {
  68. if ([self.delegate respondsToSelector:@selector(commentNunberClick)]) {
  69. [self.delegate commentNunberClick];
  70. }
  71. }
  72. - (void)changeAlignmentRightandLeft{
  73. // CGRect textSize = [self.text boundingRectWithSize:CGSizeMake(self.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : self.font} context:nil];
  74. //
  75. // CGFloat margin = (self.frame.size.width - textSize.size.width) / (self.text.length - 1);
  76. //
  77. // NSNumber *number = [NSNumber numberWithFloat:margin];
  78. // NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:self.text];
  79. // [attributeString addAttribute:(id)kCTKernAttributeName value:number range:NSMakeRange(0, self.text.length - 1)];
  80. // self.attributedText = attributeString;
  81. }
  82. #pragma mark - buttonAction
  83. - (void)commentButtonAction:(TDButton *)sender {
  84. if ([self.delegate respondsToSelector:@selector(commentInputTouch)]) {
  85. [self.delegate commentInputTouch];
  86. }
  87. }
  88. - (void)thumbButtonAction:(TDButton *)sender {
  89. //sender.selected = !sender.selected;
  90. if ([self.delegate respondsToSelector:@selector(functionTouch:)]) {
  91. [self.delegate functionTouch:sender];
  92. }
  93. }
  94. - (void)collectButtonAction:(TDButton *)sender {
  95. //sender.selected = !sender.selected;
  96. if ([self.delegate respondsToSelector:@selector(functionTouch:)]) {
  97. [self.delegate functionTouch:sender];
  98. }
  99. }
  100. - (void)sharedButtonAction:(TDButton *)sender {
  101. if ([self.delegate respondsToSelector:@selector(functionTouch:)]) {
  102. [self.delegate functionTouch:sender];
  103. }
  104. }
  105. #pragma mark - setter
  106. - (TDButton *)commentButton {
  107. if (!_commentButton) {
  108. _commentButton = [[TDButton alloc] init];
  109. _commentButton.backgroundColor = UIColorHex(#EEEEEE);
  110. _commentButton.layer.cornerRadius = 5.f;
  111. [_commentButton setTitle:@"说点什么..." forState:UIControlStateNormal];
  112. [_commentButton setTitleColor:UIColorHex(#FFFFFF) forState:UIControlStateNormal];
  113. [[_commentButton titleLabel] setFont:[UIFont systemFontOfSize:12.f]];
  114. _commentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  115. _commentButton.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, -10);
  116. [_commentButton addTarget:self action:@selector(commentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  117. }
  118. return _commentButton;
  119. }
  120. - (TDButton *)thumbButton {
  121. if (!_thumbButton) {
  122. _thumbButton = [[TDButton alloc] init];
  123. _thumbButton.tag = ThumbTag;
  124. [_thumbButton setImage:IMG(@"thumb_no") forState:UIControlStateNormal];
  125. [_thumbButton setImage:IMG(@"thumb_yes") forState:UIControlStateSelected];
  126. [_thumbButton addTarget:self action:@selector(thumbButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  127. [_thumbButton setCurrentButtonHotSize:CGSizeZero];
  128. }
  129. return _thumbButton;
  130. }
  131. - (TDButton *)collectButton {
  132. if (!_collectButton) {
  133. _collectButton = [[TDButton alloc] init];
  134. _collectButton.tag = CollectTag;
  135. [_collectButton setImage:IMG(@"收藏五角星") forState:UIControlStateNormal];
  136. [_collectButton setImage:IMG(@"icon_collect_off") forState:UIControlStateSelected];
  137. [_collectButton addTarget:self action:@selector(collectButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  138. [_collectButton setCurrentButtonHotSize:CGSizeZero];
  139. }
  140. return _collectButton;
  141. }
  142. - (TDButton *)sharedButton {
  143. if (!_sharedButton) {
  144. _sharedButton = [[TDButton alloc] init];
  145. _sharedButton.tag = SharedTag;
  146. [_sharedButton setImage:IMG(@"icon_share") forState:UIControlStateNormal];
  147. [_sharedButton setImage:IMG(@"icon_share") forState:UIControlStateSelected];
  148. [_sharedButton addTarget:self action:@selector(sharedButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  149. [_sharedButton setCurrentButtonHotSize:CGSizeZero];
  150. }
  151. return _sharedButton;
  152. }
  153. //- (UIView *)lineView{
  154. // if(_lineView){
  155. // _lineView = [[UIView alloc]init];
  156. // _lineView.backgroundColor = [UIColor blackColor];
  157. //// UIColorHex(E5E5E5);
  158. // }
  159. // return _lineView;
  160. //}
  161. @end