// // GroupSynopsisCell.m // smartRhino // // Created by niuzhen on 2020/6/15. // Copyright © 2020 tederen. All rights reserved. // #import "GroupSynopsisCell.h" #import "SynopsisCollectCell.h" #import "UILabel+YBAttributeTextTapAction.h" @interface GroupSynopsisCell() @property (nonatomic, strong) NSArray * dataArray; @property (nonatomic, assign) BOOL show; @end @implementation GroupSynopsisCell - (void)awakeFromNib { [super awakeFromNib]; self.iconV.layer.cornerRadius = 20.f; self.iconV.layer.masksToBounds = YES; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.scrollEnabled = NO; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsHorizontalScrollIndicator = NO; [self.collectionView registerNib:[UINib nibWithNibName:@"SynopsisCollectCell" bundle:nil] forCellWithReuseIdentifier:@"SynopsisCollectCell"]; self.layout = [[CollectionViewSpaceLayout alloc]init]; self.layout.sectionInsets = UIEdgeInsetsMake(2, 15, 24, 15); self.layout.lineSpacing = 9.f; self.layout.interitemSpacing = 9.f; self.layout.delegate = self; [self.collectionView setCollectionViewLayout:self.layout]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } + (GroupSynopsisCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"GroupSynopsisCell0"; GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:0]; } return cell; } + (GroupSynopsisCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"GroupSynopsisCell1"; GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:1]; } return cell; } + (GroupSynopsisCell *)configCell2:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"GroupSynopsisCell2"; GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:2]; } return cell; } + (GroupSynopsisCell *)configCell3:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"GroupSynopsisCell3"; GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:3]; } return cell; } - (void)setData:(TDGroupInfoListModel *)model { CGFloat W = (SCREEN_WIDTH - 60 - 75) * 0.25; [self.BezierOneV addSubview:[self drawTotal:@100 current:@62 width:W color:UIColorHex(0xF53D23)]]; [self.BezierTwoV addSubview:[self drawTotal:@100 current:@7 width:W color:UIColorHex(0x3B9DED)]]; [self.BezierThreeV addSubview:[self drawTotal:@100 current:@31 width:W color:UIColorHex(0xFF9B30)]]; [self.BezierFourV addSubview:[self drawTotal:@100 current:@20 width:W color:UIColorHex(0x91A5BD)]]; self.BezierOneL.text = @"博士"; self.BezierTwoL.text = @"北京"; self.BezierThreeL.text = @"80后"; self.BezierFourL.text = @"金融"; [self setUserCount:model.CommonMemberCount]; WS(weakSelf); UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { if (weakSelf.ClickMoreBlcok) { weakSelf.ClickMoreBlcok(); } }]; [self.MoreView addGestureRecognizer:tap]; self.MoreView.userInteractionEnabled = YES; } - (PNCircleChart *)drawTotal:(NSNumber *)total current:(NSNumber *)current width:(CGFloat)width color:(UIColor *)color { PNCircleChart * view = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 0, width, width) total:total current:current clockwise:YES shadow:YES shadowColor:UIColorHex(0xF1F1F1) displayCountingLabel:YES overrideLineWidth:@3.0f strokeColor:UIColorHex(0xF1F1F1)]; view.backgroundColor = [UIColor whiteColor]; [view setStrokeColor:color]; [view setStrokeColorGradientStart:color]; [view strokeChart]; return view; } - (void)setDataModel:(TDGroupInfoListModel *)model isShow:(BOOL)show { self.show = show; self.contentL.numberOfLines = show ? 0 : 3; [self.iconV sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"img_placeHolder")]; self.titleL.text = model.Name; self.nameL.text = model.UserName; [self setLabelwithText:model.Introduce]; [self.contentL layoutIfNeeded]; } //- (YYLabel *)contentL //{ // if (!_contentL) { // _contentL = [YYLabel new]; // } // return _contentL;; //} - (void)setUserCount:(NSInteger)count { self.countL.text = [NSString stringWithFormat:@"%ld人",count]; } - (void)setGroupLabel:(NSString *)name { self.dataArray = [name componentsSeparatedByString:@","]; [self.collectionView reloadData]; [self.collectionView layoutIfNeeded]; self.collectH.constant = self.collectionView.contentSize.height; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 9.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 9.f; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.dataArray.count; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { UILabel * label = [UILabel new]; label.text = self.dataArray[indexPath.item]; label.font = Kfont(14); CGFloat W = [label sizeThatFits:CGSizeMake(MAXFLOAT, 24)].width + 24; return CGSizeMake(W, 24); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SynopsisCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SynopsisCollectCell" forIndexPath:indexPath]; cell.titleL.text = self.dataArray[indexPath.item]; return cell; } - (void)setLabelwithText:(NSString *)text { if (text.length == 0) { self.contentL.text = @""; return; } NSArray * stringArr = [self getLinesArrayOfStringInText:text width:SCREEN_WIDTH - 30]; if (stringArr.count > 3) { WS(weakSelf); if (self.show) { NSString *string4 = [NSString stringWithFormat:@"%@%@",text,self.show ? @"收起" : @"更多"]; self.contentL.attributedText = [self AttributedwithText:string4 isShow:YES]; [self.contentL yb_addAttributeTapActionWithRanges:@[NSStringFromRange(NSMakeRange(string4.length - 4, 4))] tapClicked:^(UILabel *label,NSString *string, NSRange range,NSInteger index) { NSLog(@"12313131"); if (weakSelf.ShowBlcok) { weakSelf.ShowBlcok(!weakSelf.show); } }]; }else{ NSString *string1 = stringArr[0]; NSString *string2 = stringArr[1]; NSString *string3 = stringArr[2]; string3 = [string3 substringToIndex:string3.length - 5]; NSString *string4 = [NSString stringWithFormat:@"%@%@%@...%@",string1,string2,string3,self.show ? @"收起" : @"更多"]; self.contentL.attributedText = [self AttributedwithText:string4 isShow:YES]; [self.contentL yb_addAttributeTapActionWithRanges:@[NSStringFromRange(NSMakeRange(string4.length - 4, 4))] tapClicked:^(UILabel *label,NSString *string, NSRange range,NSInteger index) { NSLog(@"12313131"); if (weakSelf.ShowBlcok) { weakSelf.ShowBlcok(!weakSelf.show); } }]; } }else{ self.contentL.attributedText = [self AttributedwithText:text isShow:NO]; } } - (NSAttributedString *)AttributedwithText:(NSString *)text isShow:(BOOL)show { NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text]; [mutableAttributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, text.length)]; [mutableAttributedString addAttribute:NSForegroundColorAttributeName value:UIColorHex(0x0a0a0a) range:NSMakeRange(0, text.length - (show ? 2 : 0))]; if (show) { [mutableAttributedString addAttribute:NSForegroundColorAttributeName value:UIColorHex(0x3979D3) range:NSMakeRange(text.length - 2, 2)]; } NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init]; paraStyle.alignment = NSTextAlignmentJustified;//两端对齐 [paraStyle setLineSpacing:8];//行间距 [mutableAttributedString addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)]; return mutableAttributedString; } - (NSArray *)getLinesArrayOfStringInText:(NSString *)text width:(CGFloat)width{ UIFont *font = [UIFont systemFontOfSize:17]; CTFontRef myFont = CTFontCreateWithName(( CFStringRef)([font fontName]), [font pointSize], NULL); NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text]; [attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)myFont range:NSMakeRange(0, attStr.length)]; CFRelease(myFont); CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(( CFAttributedStringRef)attStr); CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, CGRectMake(0,0,width,MAXFLOAT)); CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL); NSArray *lines = ( NSArray *)CTFrameGetLines(frame); NSMutableArray *linesArray = [[NSMutableArray alloc]init]; for (id line in lines) { CTLineRef lineRef = (__bridge CTLineRef )line; CFRange lineRange = CTLineGetStringRange(lineRef); NSRange range = NSMakeRange(lineRange.location, lineRange.length); NSString *lineString = [text substringWithRange:range]; CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithFloat:0.0])); CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithInt:0.0])); [linesArray addObject:lineString]; } CGPathRelease(path); CFRelease( frame ); CFRelease(frameSetter); return (NSArray *)linesArray; } @end