// // GroupSynopsisCell.m // smartRhino // // Created by niuzhen on 2020/6/15. // Copyright © 2020 tederen. All rights reserved. // #import "GroupSynopsisCell.h" #import "SynopsisCollectCell.h" @implementation GroupSynopsisCell - (void)awakeFromNib { [super awakeFromNib]; 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 { 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 = @"金融"; } - (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)setContentText:(NSString *)text { [self setLabelwithText:@"王府井大街上的 “新中国第一店” 王府井百货大楼,这是新中国成立后北京建造的第一座大型百中国成立后北京建造的第一座大型百货零售商店。 从1955年至今"]; } - (void)setCollData { [self.collectionView reloadData]; self.collectH.constant = 550.f; [self.collectionView layoutIfNeeded]; } - (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 40; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { UILabel * label = [UILabel new]; label.text = indexPath.item % 2 == 0 ? @"前沿" : @"经济决策"; 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 = indexPath.item % 2 == 0 ? @"前沿" : @"经济决策"; NSLog(@"%ld",indexPath.item); return cell; } - (void)setLabelwithText:(NSString *)text { NSArray * stringArr = [self getLinesArrayOfStringInText:text width:SCREEN_WIDTH - 30]; if (stringArr.count > 3) { self.contentL.numberOfLines = 3; NSString *string1 = stringArr[0]; NSString *string2 = stringArr[1]; NSString *string3 = stringArr[2]; string3 = [string3 substringToIndex:string3.length - 4]; NSString *string4 = [NSString stringWithFormat:@"%@%@%@...",string1,string2,string3]; self.contentL.attributedText = [self AttributedwithText:string4]; self.moreBtn.hidden = NO; }else{ self.contentL.attributedText = [self AttributedwithText:text]; self.moreBtn.hidden = YES; } } - (NSAttributedString *)AttributedwithText:(NSString *)text { 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)]; 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