GroupSynopsisCell.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // GroupSynopsisCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/15.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "GroupSynopsisCell.h"
  9. #import "SynopsisCollectCell.h"
  10. @implementation GroupSynopsisCell
  11. - (void)awakeFromNib {
  12. [super awakeFromNib];
  13. self.collectionView.delegate = self;
  14. self.collectionView.dataSource = self;
  15. self.collectionView.scrollEnabled = NO;
  16. self.collectionView.showsVerticalScrollIndicator = NO;
  17. self.collectionView.showsHorizontalScrollIndicator = NO;
  18. [self.collectionView registerNib:[UINib nibWithNibName:@"SynopsisCollectCell" bundle:nil] forCellWithReuseIdentifier:@"SynopsisCollectCell"];
  19. self.layout = [[CollectionViewSpaceLayout alloc]init];
  20. self.layout.sectionInsets = UIEdgeInsetsMake(2, 15, 24, 15);
  21. self.layout.lineSpacing = 9.f;
  22. self.layout.interitemSpacing = 9.f;
  23. self.layout.delegate = self;
  24. [self.collectionView setCollectionViewLayout:self.layout];
  25. }
  26. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  27. [super setSelected:selected animated:animated];
  28. // Configure the view for the selected state
  29. }
  30. + (GroupSynopsisCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  31. static NSString *cellIdentifer = @"GroupSynopsisCell0";
  32. GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  33. if (cell == nil) {
  34. cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:0];
  35. }
  36. return cell;
  37. }
  38. + (GroupSynopsisCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  39. static NSString *cellIdentifer = @"GroupSynopsisCell1";
  40. GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  41. if (cell == nil) {
  42. cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:1];
  43. }
  44. return cell;
  45. }
  46. + (GroupSynopsisCell *)configCell2:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  47. static NSString *cellIdentifer = @"GroupSynopsisCell2";
  48. GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  49. if (cell == nil) {
  50. cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:2];
  51. }
  52. return cell;
  53. }
  54. + (GroupSynopsisCell *)configCell3:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  55. static NSString *cellIdentifer = @"GroupSynopsisCell3";
  56. GroupSynopsisCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  57. if (cell == nil) {
  58. cell = [[[NSBundle mainBundle] loadNibNamed:@"GroupSynopsisCell" owner:nil options:nil] objectAtIndex:3];
  59. }
  60. return cell;
  61. }
  62. - (void)setData
  63. {
  64. CGFloat W = (SCREEN_WIDTH - 60 - 75) * 0.25;
  65. [self.BezierOneV addSubview:[self drawTotal:@100 current:@62 width:W color:UIColorHex(0xF53D23)]];
  66. [self.BezierTwoV addSubview:[self drawTotal:@100 current:@7 width:W color:UIColorHex(0x3B9DED)]];
  67. [self.BezierThreeV addSubview:[self drawTotal:@100 current:@31 width:W color:UIColorHex(0xFF9B30)]];
  68. [self.BezierFourV addSubview:[self drawTotal:@100 current:@20 width:W color:UIColorHex(0x91A5BD)]];
  69. self.BezierOneL.text = @"博士";
  70. self.BezierTwoL.text = @"北京";
  71. self.BezierThreeL.text = @"80后";
  72. self.BezierFourL.text = @"金融";
  73. }
  74. - (PNCircleChart *)drawTotal:(NSNumber *)total current:(NSNumber *)current width:(CGFloat)width color:(UIColor *)color
  75. {
  76. PNCircleChart * view = [[PNCircleChart alloc] initWithFrame:CGRectMake(0, 0, width, width)
  77. total:total
  78. current:current
  79. clockwise:YES
  80. shadow:YES
  81. shadowColor:UIColorHex(0xF1F1F1)
  82. displayCountingLabel:YES
  83. overrideLineWidth:@3.0f
  84. strokeColor:UIColorHex(0xF1F1F1)];
  85. view.backgroundColor = [UIColor whiteColor];
  86. [view setStrokeColor:color];
  87. [view setStrokeColorGradientStart:color];
  88. [view strokeChart];
  89. return view;
  90. }
  91. - (void)setContentText:(NSString *)text
  92. {
  93. [self setLabelwithText:@"王府井大街上的 “新中国第一店” 王府井百货大楼,这是新中国成立后北京建造的第一座大型百中国成立后北京建造的第一座大型百货零售商店。 从1955年至今"];
  94. }
  95. - (void)setCollData
  96. {
  97. [self.collectionView reloadData];
  98. self.collectH.constant = 550.f;
  99. [self.collectionView layoutIfNeeded];
  100. }
  101. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  102. {
  103. return 9.f;
  104. }
  105. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  106. {
  107. return 9.f;
  108. }
  109. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  110. {
  111. return 40;
  112. }
  113. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  114. {
  115. return 1;
  116. }
  117. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  118. {
  119. UILabel * label = [UILabel new];
  120. label.text = indexPath.item % 2 == 0 ? @"前沿" : @"经济决策";
  121. label.font = Kfont(14);
  122. CGFloat W = [label sizeThatFits:CGSizeMake(MAXFLOAT, 24)].width + 24;
  123. return CGSizeMake(W, 24);
  124. }
  125. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  126. {
  127. SynopsisCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SynopsisCollectCell" forIndexPath:indexPath];
  128. cell.titleL.text = indexPath.item % 2 == 0 ? @"前沿" : @"经济决策";
  129. NSLog(@"%ld",indexPath.item);
  130. return cell;
  131. }
  132. - (void)setLabelwithText:(NSString *)text
  133. {
  134. NSArray * stringArr = [self getLinesArrayOfStringInText:text width:SCREEN_WIDTH - 30];
  135. if (stringArr.count > 3) {
  136. self.contentL.numberOfLines = 3;
  137. NSString *string1 = stringArr[0];
  138. NSString *string2 = stringArr[1];
  139. NSString *string3 = stringArr[2];
  140. string3 = [string3 substringToIndex:string3.length - 4];
  141. NSString *string4 = [NSString stringWithFormat:@"%@%@%@...",string1,string2,string3];
  142. self.contentL.attributedText = [self AttributedwithText:string4];
  143. self.moreBtn.hidden = NO;
  144. }else{
  145. self.contentL.attributedText = [self AttributedwithText:text];
  146. self.moreBtn.hidden = YES;
  147. }
  148. }
  149. - (NSAttributedString *)AttributedwithText:(NSString *)text
  150. {
  151. NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:text];
  152. [mutableAttributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, text.length)];
  153. [mutableAttributedString addAttribute:NSForegroundColorAttributeName value:UIColorHex(0x0a0a0a) range:NSMakeRange(0, text.length)];
  154. NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
  155. paraStyle.alignment = NSTextAlignmentJustified;//两端对齐
  156. [paraStyle setLineSpacing:8];//行间距
  157. [mutableAttributedString addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, text.length)];
  158. return mutableAttributedString;
  159. }
  160. - (NSArray *)getLinesArrayOfStringInText:(NSString *)text width:(CGFloat)width{
  161. UIFont *font = [UIFont systemFontOfSize:17];
  162. CTFontRef myFont = CTFontCreateWithName(( CFStringRef)([font fontName]), [font pointSize], NULL);
  163. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
  164. [attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)myFont range:NSMakeRange(0, attStr.length)];
  165. CFRelease(myFont);
  166. CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(( CFAttributedStringRef)attStr);
  167. CGMutablePathRef path = CGPathCreateMutable();
  168. CGPathAddRect(path, NULL, CGRectMake(0,0,width,MAXFLOAT));
  169. CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
  170. NSArray *lines = ( NSArray *)CTFrameGetLines(frame);
  171. NSMutableArray *linesArray = [[NSMutableArray alloc]init];
  172. for (id line in lines) {
  173. CTLineRef lineRef = (__bridge CTLineRef )line;
  174. CFRange lineRange = CTLineGetStringRange(lineRef);
  175. NSRange range = NSMakeRange(lineRange.location, lineRange.length);
  176. NSString *lineString = [text substringWithRange:range];
  177. CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithFloat:0.0]));
  178. CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithInt:0.0]));
  179. [linesArray addObject:lineString];
  180. }
  181. CGPathRelease(path);
  182. CFRelease( frame );
  183. CFRelease(frameSetter);
  184. return (NSArray *)linesArray;
  185. }
  186. @end