NotifyMessageCell.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // NotifyMessageCell.m
  3. // MusicGradeExam
  4. //
  5. // Created by Kyle on 2020/7/15.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "NotifyMessageCell.h"
  9. @interface NotifyMessageCell ()
  10. @property (weak, nonatomic) IBOutlet UIView *redDot;
  11. @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
  12. @property (weak, nonatomic) IBOutlet UILabel *topMessage;
  13. @property (weak, nonatomic) IBOutlet UILabel *descMessage;
  14. @property (nonatomic, strong) MessageListModel *model;
  15. @end
  16. @implementation NotifyMessageCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. self.selectionStyle = UITableViewCellSelectionStyleNone;
  21. }
  22. - (void)configCellWithSource:(MessageListModel *)sourceModel {
  23. self.model = sourceModel;
  24. self.isRead = sourceModel.readStatus == 1 ? YES : NO;
  25. NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
  26. dateFormatter.timeZone = [NSTimeZone systemTimeZone];
  27. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  28. NSDate *messageDate = [dateFormatter dateFromString:sourceModel.modifyOn];
  29. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  30. NSDate *currentDate = [NSDate date];
  31. NSString *today = [dateFormatter stringFromDate:currentDate];
  32. NSString *messageDateStr = [dateFormatter stringFromDate:messageDate];
  33. NSString *dateStr = @"";
  34. if ([messageDateStr isEqualToString:today]) {
  35. [dateFormatter setDateFormat:@"HH:mm"];
  36. dateStr = [dateFormatter stringFromDate:messageDate];
  37. }
  38. else {
  39. [dateFormatter setDateFormat:@"MM-dd"];
  40. dateStr = [dateFormatter stringFromDate:messageDate];
  41. }
  42. self.timeLabel.text = [NSString returnNoNullStringWithString:dateStr];
  43. self.topMessage.text = [NSString returnNoNullStringWithString:sourceModel.title];
  44. NSString *messgage = [NSString returnNoNullStringWithString:sourceModel.content];
  45. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  46. [paragraphStyle setLineSpacing:4];//调整行间距
  47. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:messgage attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:HexRGB(0x808080)}];
  48. self.descMessage.attributedText = attrStr;
  49. }
  50. - (void)setIsRead:(BOOL)isRead {
  51. _isRead = isRead;
  52. self.redDot.hidden = isRead;
  53. }
  54. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  55. [super setSelected:selected animated:animated];
  56. // Configure the view for the selected state
  57. }
  58. @end