ArticleTextCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // ArticleTextCell.m
  3. // smartRhino
  4. //
  5. // Created by 潘洪波 on 2019/11/18.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "ArticleTextCell.h"
  9. #import "UILabel+Extension.h"
  10. @implementation ArticleTextCell
  11. - (void)awakeFromNib {
  12. [super awakeFromNib];
  13. // Initialization code
  14. }
  15. - (void)layoutSubviews{
  16. [super layoutSubviews];
  17. }
  18. - (void)setContent:(NSString *)content{
  19. _content = content;
  20. UIFont *font = [UIFont fontWithName:@"PingFang-SC-Regular" size:18];
  21. // NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
  22. // paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
  23. // paraStyle.alignment = NSTextAlignmentNatural;
  24. // paraStyle.lineSpacing = 1; //设置行间距
  25. // paraStyle.hyphenationFactor = 0.0;
  26. // paraStyle.firstLineHeadIndent = 30;
  27. // //设置字间距 NSKernAttributeName:@1.5f
  28. // NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@(2)
  29. // };
  30. // NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:content attributes:dic];
  31. //
  32. // self.contentLab.attributedText = attributeStr;
  33. self.contentLab.text = [self checkContent:content];
  34. [ZYCTool setLabel:self.contentLab withSpace:9 withFont:font setLineSpace:0 setTextSpace:0];
  35. self.contentLab.numberOfLines = 0;
  36. [self.contentLab sizeToFit];
  37. // self.contentLab.text = content;
  38. // self.contentLab.font = font;
  39. // self.contentLab.numberOfLines = 0;
  40. // [self.contentLab sizeToFit];
  41. }
  42. - (NSString *)checkContent:(NSString *)content
  43. {
  44. NSString *string = [content stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
  45. NSString *changeStr = [string stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "];
  46. return changeStr;
  47. }
  48. + (CGFloat)cellHeight:(NSString *)text{
  49. UIFont *font = [UIFont fontWithName:@"PingFang-SC-Regular" size:18];
  50. // NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
  51. // paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
  52. // paraStyle.alignment = NSTextAlignmentNatural;
  53. // paraStyle.lineSpacing = 1; //设置行间距
  54. // paraStyle.hyphenationFactor = 0.0;
  55. // paraStyle.firstLineHeadIndent = 30;
  56. // //设置字间距 NSKernAttributeName:@1.5f
  57. // NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@(2)};
  58. // NSString *tmpStr = [[self alloc] checkContent:text];
  59. CGSize size = [text sizeWithFont:font byWidth:SCREEN_WIDTH-24 textLineSpacing:9];
  60. // return size.height + 20 + 10;
  61. return size.height + 30 ;
  62. }
  63. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  64. [super setSelected:selected animated:animated];
  65. // Configure the view for the selected state
  66. }
  67. @end