CourseDescAlertCell.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // CourseDescAlertCell.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2024/11/19.
  6. //
  7. #import "CourseDescAlertCell.h"
  8. @interface CourseDescAlertCell ()
  9. @property (weak, nonatomic) IBOutlet UILabel *tipsTitle;
  10. @property (weak, nonatomic) IBOutlet UILabel *tipsDesc;
  11. @end
  12. @implementation CourseDescAlertCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. // Initialization code
  16. }
  17. - (void)configWithTitle:(NSString *)title desc:(NSString *)desc {
  18. self.tipsTitle.text = [NSString returnNoNullStringWithString:title];
  19. NSMutableParagraphStyle *paragraphStyle = [self getParagraphStyleWithFont:[UIFont systemFontOfSize:13.0f] lineHeight:22.0f];
  20. CGFloat baselineOffset = [self getBaseOffline:[UIFont systemFontOfSize:13.0f] lineHeight:22.0f];
  21. NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:desc attributes:@{NSParagraphStyleAttributeName:paragraphStyle, NSBaselineOffsetAttributeName:@(baselineOffset),NSFontAttributeName:[UIFont systemFontOfSize:13.0f]}];
  22. self.tipsDesc.attributedText = attrs;
  23. }
  24. - (CGFloat)getBaseOffline:(UIFont *)font lineHeight:(CGFloat)lineHeight {
  25. CGFloat baselineOffset = (lineHeight - font.lineHeight) / 4;
  26. return baselineOffset;
  27. }
  28. - (NSMutableParagraphStyle *)getParagraphStyleWithFont:(UIFont *)font lineHeight:(CGFloat)lineHeigh {
  29. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  30. paragraphStyle.maximumLineHeight = lineHeigh;
  31. paragraphStyle.minimumLineHeight = lineHeigh;
  32. return paragraphStyle;
  33. }
  34. @end