UserDetailBodyView.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // UserDetailBodyView.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/10/18.
  6. //
  7. #import "UserDetailBodyView.h"
  8. #import "RecentMusicView.h"
  9. @interface UserDetailBodyView ()
  10. @property (weak, nonatomic) IBOutlet UIImageView *userAvatar;
  11. @property (weak, nonatomic) IBOutlet UILabel *userName;
  12. @property (weak, nonatomic) IBOutlet UIImageView *memberImage;
  13. @property (weak, nonatomic) IBOutlet UILabel *userSex;
  14. @property (weak, nonatomic) IBOutlet UILabel *userSubject;
  15. @property (weak, nonatomic) IBOutlet UIView *subjectView;
  16. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *subjectViewHeight;
  17. @property (weak, nonatomic) IBOutlet UILabel *userIdLabel;
  18. @property (nonatomic, copy) RecentMusicCallback callback;
  19. @end
  20. @implementation UserDetailBodyView
  21. - (void)awakeFromNib {
  22. [super awakeFromNib];
  23. }
  24. + (instancetype)shareInstance {
  25. UserDetailBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"UserDetailBodyView" owner:nil options:nil] firstObject];
  26. return view;
  27. }
  28. - (void)configUserMessage:(ChatUserInfo *)userInfo musicArray:(NSMutableArray *)musicArray callback:(RecentMusicCallback)callback {
  29. if (callback) {
  30. self.callback = callback;
  31. }
  32. NSString *viperImage = @"";
  33. if (userInfo.isVip == 1) {
  34. self.userAvatar.layer.borderColor = HexRGB(0xFFE0B9).CGColor;
  35. viperImage = @"mine_vip";
  36. }
  37. else {
  38. self.userAvatar.layer.borderColor = HexRGB(0xffffff).CGColor;
  39. viperImage = @"mine_nomal";
  40. }
  41. [self.memberImage setImage:[UIImage imageNamed:viperImage]];
  42. [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[userInfo.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  43. self.userName.text = [NSString returnNoNullStringWithString:userInfo.username];
  44. self.userIdLabel.text = [NSString stringWithFormat:@"学号:%.0f",userInfo.userId];
  45. self.userSubject.text = [NSString returnNoNullStringWithString:userInfo.subjectName];
  46. NSString *sexString = userInfo.gender == 1 ? @"男生" : @"女生";
  47. self.userSex.text = sexString;
  48. [self evaluateSource:musicArray];
  49. }
  50. - (void)evaluateSource:(NSArray *)musicArray {
  51. [self.subjectView removeAllSubViews];
  52. NSInteger count = musicArray.count > 3 ? 3 : musicArray.count;
  53. for (NSInteger i = 0; i < count; i++) {
  54. // 添加按钮
  55. RecentMusicView *musicView = [RecentMusicView shareInstance];
  56. musicView.frame = CGRectMake(0, 84 * i, KPortraitWidth - 28, 84);
  57. BOOL hideLineView = i == count - 1 ? YES : NO;
  58. MJWeakSelf;
  59. [musicView configWithMusicModel:musicArray[i] hiddenLineView:hideLineView callback:^(NSString * _Nonnull songId) {
  60. if (weakSelf.callback) {
  61. weakSelf.callback(songId);
  62. }
  63. }];
  64. [self.subjectView addSubview:musicView];
  65. }
  66. }
  67. + (CGFloat)getViewHeight {
  68. return 590.0f;
  69. }
  70. /*
  71. // Only override drawRect: if you perform custom drawing.
  72. // An empty implementation adversely affects performance during animation.
  73. - (void)drawRect:(CGRect)rect {
  74. // Drawing code
  75. }
  76. */
  77. @end