SeatContentView.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // SeatContentView.m
  3. // StudentDaya
  4. //
  5. // Created by Kyle on 2022/2/21.
  6. // Copyright © 2022 DayaMusic. All rights reserved.
  7. //
  8. #import "SeatContentView.h"
  9. #import <RongIMKit/RongIMKit.h>
  10. @interface SeatMemberView : UIView
  11. @property (nonatomic, strong) UIImageView *userAvatar;
  12. @property (nonatomic, strong) NSString *userId;
  13. @property (nonatomic, strong) NSString *userName;
  14. @property (nonatomic, strong) UILabel *nameLabel;
  15. - (instancetype)initViewWithFrame:(CGRect)frame useId:(NSString *)userId;
  16. @end
  17. @implementation SeatMemberView
  18. - (instancetype)initViewWithFrame:(CGRect)frame useId:(NSString *)userId {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. self.userId = userId;
  22. [self setupUI];
  23. }
  24. return self;
  25. }
  26. - (void)setupUI {
  27. self.backgroundColor = [UIColor clearColor];
  28. if ([self.userId isEqualToString:UserDefault(RongCloudID)]) { // 自己
  29. [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[UserDefault(AvatarUrlKey) getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  30. self.userAvatar.layer.borderColor = HexRGB(0xf37f17).CGColor;
  31. self.userAvatar.layer.borderWidth = 1.0f;
  32. [self addSubview:self.userAvatar];
  33. [self.userAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.centerX.mas_equalTo(self.mas_centerX);
  35. make.top.mas_equalTo(self.mas_top).offset(4);
  36. make.width.height.mas_equalTo(46);
  37. }];
  38. UIView *bgView = [[UIView alloc] initWithFrame:CGRectZero];
  39. bgView.layer.cornerRadius = 7.0f;
  40. bgView.backgroundColor = HexRGB(0xf37f17);
  41. [self addSubview:bgView];
  42. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.centerX.mas_equalTo(self.mas_centerX);
  44. make.left.mas_greaterThanOrEqualTo(self.mas_left).offset(5);
  45. make.height.mas_equalTo(15);
  46. make.top.mas_equalTo(self.userAvatar.mas_bottom).offset(2);
  47. }];
  48. [bgView addSubview:self.nameLabel];
  49. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerX.mas_equalTo(bgView.mas_centerX);
  51. make.centerY.mas_equalTo(bgView.mas_centerY);
  52. make.left.mas_equalTo(bgView.mas_left).offset(3);
  53. make.right.mas_equalTo(bgView.mas_right).offset(-3);
  54. }];
  55. self.nameLabel.font = [UIFont systemFontOfSize:9.0f weight:UIFontWeightMedium];
  56. self.nameLabel.text = [NSString returnNoNullStringWithString:[RCIMClient sharedRCIMClient].currentUserInfo.name];
  57. }
  58. else { // 其他人
  59. [self.userAvatar setImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  60. [self addSubview:self.userAvatar];
  61. [self.userAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.centerX.mas_equalTo(self.mas_centerX);
  63. make.top.mas_equalTo(self.mas_top).offset(4);
  64. make.width.height.mas_equalTo(46);
  65. }];
  66. [self addSubview:self.nameLabel];
  67. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.right.mas_equalTo(self);
  69. make.top.mas_equalTo(self.userAvatar.mas_bottom).offset(2);
  70. make.height.mas_equalTo(13);
  71. }];
  72. [self queryUserInfoWithUserId:self.userId];
  73. }
  74. }
  75. - (UILabel *)nameLabel {
  76. if (!_nameLabel) {
  77. _nameLabel = [[UILabel alloc] init];
  78. _nameLabel.textColor = [UIColor whiteColor];
  79. _nameLabel.font = [UIFont systemFontOfSize:9.0f];
  80. _nameLabel.textAlignment = NSTextAlignmentCenter;
  81. }
  82. return _nameLabel;
  83. }
  84. - (UIImageView *)userAvatar {
  85. if (!_userAvatar) {
  86. _userAvatar = [[UIImageView alloc] init];
  87. _userAvatar.contentMode = UIViewContentModeScaleAspectFill;
  88. _userAvatar.layer.cornerRadius = 23.0f;
  89. [_userAvatar.layer setMasksToBounds:YES];
  90. }
  91. return _userAvatar;
  92. }
  93. - (void)queryUserInfoWithUserId:(NSString *)userId {
  94. [KSNetworkingManager imUserFriendQueryDetail:KS_POST userId:userId success:^(NSDictionary * _Nonnull dic) {
  95. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  96. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  97. if (self) {
  98. self.nameLabel.text = [result stringValueForKey:@"friendNickname"];
  99. [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[[result stringValueForKey:@"friendAvatar"] getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  100. }
  101. else {
  102. NSLog(@"-delloc------");
  103. }
  104. }
  105. else {
  106. if (self) {
  107. self.nameLabel.text = @"连麦用户";
  108. }
  109. }
  110. } faliure:^(NSError * _Nonnull error) {
  111. if (self) {
  112. self.nameLabel.text = @"连麦用户";
  113. }
  114. }];
  115. }
  116. @end
  117. @implementation SeatContentView
  118. - (instancetype)init {
  119. self = [super init];
  120. if (self) {
  121. self.backgroundColor = [UIColor clearColor];
  122. }
  123. return self;
  124. }
  125. - (void)refreshSeatUI {
  126. [self removeAllSubviews:self];
  127. CGFloat space = 10;
  128. CGFloat width = 54;
  129. CGFloat height = 70;
  130. NSMutableArray *seatArray = [self.seatMemberArray mutableCopy];
  131. for (NSInteger index = 0; index < seatArray.count; index++) {
  132. NSString *userId = seatArray[index];
  133. CGRect frame = CGRectMake(space + index * (width + space), space, width, height);
  134. SeatMemberView *memberView = [[SeatMemberView alloc] initViewWithFrame:frame useId:userId];
  135. [self addSubview:memberView];
  136. }
  137. }
  138. - (void)removeAllSubviews:(UIView *)view {
  139. while (view.subviews.count) {
  140. [view.subviews.lastObject removeFromSuperview];
  141. }
  142. }
  143. /*
  144. // Only override drawRect: if you perform custom drawing.
  145. // An empty implementation adversely affects performance during animation.
  146. - (void)drawRect:(CGRect)rect {
  147. // Drawing code
  148. }
  149. */
  150. @end