// // CommentSetView.m // TheoryNetwork // // Created by tederen on 2019/9/26. // Copyright © 2019 tederen. All rights reserved. // #import "CommentSetView.h" @interface CommentSetView () @property (nonatomic, strong) TDButton *commentButton; @end @implementation CommentSetView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor whiteColor]; // [self addSubview:self.lineView]; [self addSubview:self.commentButton]; [self addSubview:self.thumbButton]; [self addSubview:self.collectButton]; [self addSubview:self.sharedButton]; CGFloat height = frame.size.height; CGFloat rightMargin = 15.f; _sharedButton.frame = CGRectMake(kGXScreenWidth - rightMargin - 18.f, (height-18.f)/2.0, 18.f, 18.f); rightMargin += 18.f + 25.f; _collectButton.frame = CGRectMake(kGXScreenWidth - rightMargin - 18.f, (height-18.f)/2.0, 18.f, 18.f); rightMargin += 18.f + 25.f; _thumbButton.frame = CGRectMake(kGXScreenWidth - rightMargin - 18.f, (height-18.f)/2.0, 18.f, 18.f); rightMargin += 18.f + 34.f; _commentButton.frame = CGRectMake(15.f, 7, kGXScreenWidth - rightMargin - 15, 45-7-7); UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,0,kGXScreenWidth, 0.5f)]; lineView.backgroundColor = UIColorHex(E5E5E5); [self addSubview:lineView]; UILabel *numLabel = [[UILabel alloc]init]; numLabel.textColor = UIColorHex(999999); numLabel.text = @"0人"; numLabel.numberOfLines = 0; numLabel.font = [UIFont systemFontOfSize:8.f]; //[ZYCTool setLabel:numLabel withSpace:0 withFont:[UIFont systemFontOfSize:8.f] setLineSpace:0 setTextSpace:0.f]; CGSize numberSize = [numLabel sizeThatFits:CGSizeMake(41, 31)]; numLabel.frame = CGRectMake(kGXScreenWidth - rightMargin - numberSize.width-5 ,11,numberSize.width, numberSize.height); [self addSubview:numLabel]; self.numLabel = numLabel; self.numLabel.textAlignment = NSTextAlignmentCenter; UILabel *numLabelb = [[UILabel alloc]init]; numLabelb.textColor = UIColorHex(999999); numLabelb.text = @"评 论"; numLabelb.textAlignment = NSTextAlignmentCenter; numLabelb.numberOfLines = 0; numLabelb.font = [UIFont systemFontOfSize:7]; numLabelb.frame = CGRectMake(kGXScreenWidth - rightMargin - numberSize.width - 10 ,6 + 9 + numberSize.height,numberSize.width + 10, numberSize.height); [self addSubview:numLabelb]; UIView *verticalView = [[UIView alloc]initWithFrame:CGRectMake(kGXScreenWidth - rightMargin - numberSize.width - 10,9,0.5, 45-7-7-4)]; verticalView.backgroundColor = UIColorHex(#CCCCCC) ; [self addSubview:verticalView]; self.commentNumberBtn = [TDButton new]; [self.commentNumberBtn addTarget:self action:@selector(commentNunberClick) forControlEvents:UIControlEventTouchUpInside]; self.commentNumberBtn.frame = CGRectMake(kGXScreenWidth - rightMargin - numberSize.width - 5, 0, numberSize.width + 10, self.height); [self addSubview:self.commentNumberBtn]; [_collectButton setButtonBadge:0]; [_thumbButton setButtonBadge:0]; [_sharedButton setButtonBadge:0]; } return self; } - (void)commentNunberClick { if ([self.delegate respondsToSelector:@selector(commentNunberClick)]) { [self.delegate commentNunberClick]; } } - (void)changeAlignmentRightandLeft{ // CGRect textSize = [self.text boundingRectWithSize:CGSizeMake(self.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : self.font} context:nil]; // // CGFloat margin = (self.frame.size.width - textSize.size.width) / (self.text.length - 1); // // NSNumber *number = [NSNumber numberWithFloat:margin]; // NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:self.text]; // [attributeString addAttribute:(id)kCTKernAttributeName value:number range:NSMakeRange(0, self.text.length - 1)]; // self.attributedText = attributeString; } #pragma mark - buttonAction - (void)commentButtonAction:(TDButton *)sender { if ([self.delegate respondsToSelector:@selector(commentInputTouch)]) { [self.delegate commentInputTouch]; } } - (void)thumbButtonAction:(TDButton *)sender { //sender.selected = !sender.selected; if ([self.delegate respondsToSelector:@selector(functionTouch:)]) { [self.delegate functionTouch:sender]; } } - (void)collectButtonAction:(TDButton *)sender { //sender.selected = !sender.selected; if ([self.delegate respondsToSelector:@selector(functionTouch:)]) { [self.delegate functionTouch:sender]; } } - (void)sharedButtonAction:(TDButton *)sender { if ([self.delegate respondsToSelector:@selector(functionTouch:)]) { [self.delegate functionTouch:sender]; } } #pragma mark - setter - (TDButton *)commentButton { if (!_commentButton) { _commentButton = [[TDButton alloc] init]; _commentButton.backgroundColor = UIColorHex(#EEEEEE); _commentButton.layer.cornerRadius = 5.f; [_commentButton setTitle:@"说点什么..." forState:UIControlStateNormal]; [_commentButton setTitleColor:UIColorHex(#FFFFFF) forState:UIControlStateNormal]; [[_commentButton titleLabel] setFont:[UIFont systemFontOfSize:12.f]]; _commentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; _commentButton.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, -10); [_commentButton addTarget:self action:@selector(commentButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _commentButton; } - (TDButton *)thumbButton { if (!_thumbButton) { _thumbButton = [[TDButton alloc] init]; _thumbButton.tag = ThumbTag; [_thumbButton setImage:IMG(@"thumb_no") forState:UIControlStateNormal]; [_thumbButton setImage:IMG(@"thumb_yes") forState:UIControlStateSelected]; [_thumbButton addTarget:self action:@selector(thumbButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [_thumbButton setCurrentButtonHotSize:CGSizeZero]; } return _thumbButton; } - (TDButton *)collectButton { if (!_collectButton) { _collectButton = [[TDButton alloc] init]; _collectButton.tag = CollectTag; [_collectButton setImage:IMG(@"收藏五角星") forState:UIControlStateNormal]; [_collectButton setImage:IMG(@"icon_collect_off") forState:UIControlStateSelected]; [_collectButton addTarget:self action:@selector(collectButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [_collectButton setCurrentButtonHotSize:CGSizeZero]; } return _collectButton; } - (TDButton *)sharedButton { if (!_sharedButton) { _sharedButton = [[TDButton alloc] init]; _sharedButton.tag = SharedTag; [_sharedButton setImage:IMG(@"icon_share") forState:UIControlStateNormal]; [_sharedButton setImage:IMG(@"icon_share") forState:UIControlStateSelected]; [_sharedButton addTarget:self action:@selector(sharedButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [_sharedButton setCurrentButtonHotSize:CGSizeZero]; } return _sharedButton; } //- (UIView *)lineView{ // if(_lineView){ // _lineView = [[UIView alloc]init]; // _lineView.backgroundColor = [UIColor blackColor]; //// UIColorHex(E5E5E5); // } // return _lineView; //} @end