SeatContentView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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) NSString *userId;
  12. @property (nonatomic, strong) NSString *userName;
  13. @property (nonatomic, strong) UILabel *nameLabel;
  14. - (instancetype)initViewWithFrame:(CGRect)frame useId:(NSString *)userId;
  15. @end
  16. @implementation SeatMemberView
  17. - (instancetype)initViewWithFrame:(CGRect)frame useId:(NSString *)userId {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.userId = userId;
  21. [self setupUI];
  22. }
  23. return self;
  24. }
  25. - (void)setupUI {
  26. self.backgroundColor = [UIColor clearColor];
  27. if ([self.userId isEqualToString:UserDefault(UIDKey)]) { // 自己
  28. UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seat_mine"]];
  29. [self addSubview:bgImage];
  30. [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.centerX.mas_equalTo(self.mas_centerX);
  32. make.top.mas_equalTo(self.mas_top);
  33. make.width.height.mas_equalTo(54);
  34. }];
  35. UIView *bgView = [[UIView alloc] initWithFrame:CGRectZero];
  36. bgView.layer.cornerRadius = 7.0f;
  37. bgView.backgroundColor = HexRGB(0xf37f17);
  38. [self addSubview:bgView];
  39. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.centerX.mas_equalTo(self.mas_centerX);
  41. make.left.mas_greaterThanOrEqualTo(self.mas_left).offset(5);
  42. make.height.mas_equalTo(15);
  43. make.top.mas_equalTo(bgImage.mas_bottom).offset(-2);
  44. }];
  45. [bgView addSubview:self.nameLabel];
  46. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerX.mas_equalTo(bgView.mas_centerX);
  48. make.centerY.mas_equalTo(bgView.mas_centerY);
  49. make.left.mas_equalTo(bgView.mas_left).offset(6);
  50. make.right.mas_equalTo(bgView.mas_right).offset(-6);
  51. }];
  52. self.nameLabel.font = [UIFont systemFontOfSize:9.0f weight:UIFontWeightMedium];
  53. self.nameLabel.text = [NSString returnNoNullStringWithString:[RCIMClient sharedRCIMClient].currentUserInfo.name];
  54. }
  55. else { // 其他人
  56. UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seat_other"]];
  57. [self addSubview:bgImage];
  58. [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.centerX.mas_equalTo(self.mas_centerX);
  60. make.top.mas_equalTo(self.mas_top).offset(4);
  61. make.width.height.mas_equalTo(46);
  62. }];
  63. [self addSubview:self.nameLabel];
  64. [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.right.mas_equalTo(self);
  66. make.top.mas_equalTo(bgImage.mas_bottom).offset(2);
  67. make.height.mas_equalTo(13);
  68. }];
  69. [self queryUserInfoWithUserId:self.userId];
  70. }
  71. }
  72. - (UILabel *)nameLabel {
  73. if (!_nameLabel) {
  74. _nameLabel = [[UILabel alloc] init];
  75. _nameLabel.textColor = [UIColor whiteColor];
  76. _nameLabel.font = [UIFont systemFontOfSize:9.0f];
  77. _nameLabel.textAlignment = NSTextAlignmentCenter;
  78. }
  79. return _nameLabel;
  80. }
  81. - (void)queryUserInfoWithUserId:(NSString *)userId {
  82. [KSNetworkingManager imUserFriendQueryDetail:KS_POST userId:userId success:^(NSDictionary * _Nonnull dic) {
  83. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  84. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  85. self.nameLabel.text = [result stringValueForKey:@"friendNickname"];
  86. }
  87. else {
  88. self.nameLabel.text = @"连麦用户";
  89. }
  90. } faliure:^(NSError * _Nonnull error) {
  91. self.nameLabel.text = @"连麦用户";
  92. }];
  93. }
  94. @end
  95. @implementation SeatContentView
  96. - (instancetype)init {
  97. self = [super init];
  98. if (self) {
  99. self.backgroundColor = [UIColor clearColor];
  100. }
  101. return self;
  102. }
  103. - (void)refreshSeatUI {
  104. [self removeAllSubViews];
  105. CGFloat space = 10;
  106. CGFloat width = 54;
  107. CGFloat height = 70;
  108. for (NSInteger index = 0; index < self.seatMemberArray.count; index++) {
  109. NSString *userId = self.seatMemberArray[index];
  110. CGRect frame = CGRectMake(space + index * (width + space), space, width, height);
  111. SeatMemberView *memberView = [[SeatMemberView alloc] initViewWithFrame:frame useId:userId];
  112. [self addSubview:memberView];
  113. }
  114. }
  115. /*
  116. // Only override drawRect: if you perform custom drawing.
  117. // An empty implementation adversely affects performance during animation.
  118. - (void)drawRect:(CGRect)rect {
  119. // Drawing code
  120. }
  121. */
  122. @end