123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //
- // SeatContentView.m
- // StudentDaya
- //
- // Created by Kyle on 2022/2/21.
- // Copyright © 2022 DayaMusic. All rights reserved.
- //
- #import "SeatContentView.h"
- #import <RongIMKit/RongIMKit.h>
- @interface SeatMemberView : UIView
- @property (nonatomic, strong) UIImageView *userAvatar;
- @property (nonatomic, strong) NSString *userId;
- @property (nonatomic, strong) NSString *userName;
- @property (nonatomic, strong) UILabel *nameLabel;
- - (instancetype)initViewWithFrame:(CGRect)frame useId:(NSString *)userId;
- @end
- @implementation SeatMemberView
- - (instancetype)initViewWithFrame:(CGRect)frame useId:(NSString *)userId {
- self = [super initWithFrame:frame];
- if (self) {
- self.userId = userId;
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- self.backgroundColor = [UIColor clearColor];
-
- if ([self.userId isEqualToString:UserDefault(RongCloudID)]) { // 自己
- [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[UserDefault(AvatarUrlKey) getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- self.userAvatar.layer.borderColor = HexRGB(0xf37f17).CGColor;
- self.userAvatar.layer.borderWidth = 1.0f;
- [self addSubview:self.userAvatar];
- [self.userAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.mas_centerX);
- make.top.mas_equalTo(self.mas_top).offset(4);
- make.width.height.mas_equalTo(46);
- }];
- UIView *bgView = [[UIView alloc] initWithFrame:CGRectZero];
- bgView.layer.cornerRadius = 7.0f;
- bgView.backgroundColor = HexRGB(0xf37f17);
- [self addSubview:bgView];
-
- [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.mas_centerX);
- make.left.mas_greaterThanOrEqualTo(self.mas_left).offset(5);
- make.height.mas_equalTo(15);
- make.top.mas_equalTo(self.userAvatar.mas_bottom).offset(2);
- }];
-
- [bgView addSubview:self.nameLabel];
- [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(bgView.mas_centerX);
- make.centerY.mas_equalTo(bgView.mas_centerY);
- make.left.mas_equalTo(bgView.mas_left).offset(3);
- make.right.mas_equalTo(bgView.mas_right).offset(-3);
- }];
-
- self.nameLabel.font = [UIFont systemFontOfSize:9.0f weight:UIFontWeightMedium];
- self.nameLabel.text = [NSString returnNoNullStringWithString:[RCIMClient sharedRCIMClient].currentUserInfo.name];
- }
- else { // 其他人
- [self.userAvatar setImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- [self addSubview:self.userAvatar];
- [self.userAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.mas_centerX);
- make.top.mas_equalTo(self.mas_top).offset(4);
- make.width.height.mas_equalTo(46);
- }];
-
- [self addSubview:self.nameLabel];
- [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self);
- make.top.mas_equalTo(self.userAvatar.mas_bottom).offset(2);
- make.height.mas_equalTo(13);
- }];
- [self queryUserInfoWithUserId:self.userId];
- }
- }
- - (UILabel *)nameLabel {
- if (!_nameLabel) {
- _nameLabel = [[UILabel alloc] init];
- _nameLabel.textColor = [UIColor whiteColor];
- _nameLabel.font = [UIFont systemFontOfSize:9.0f];
- _nameLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _nameLabel;
- }
- - (UIImageView *)userAvatar {
- if (!_userAvatar) {
- _userAvatar = [[UIImageView alloc] init];
- _userAvatar.contentMode = UIViewContentModeScaleAspectFill;
- _userAvatar.layer.cornerRadius = 23.0f;
- [_userAvatar.layer setMasksToBounds:YES];
- }
- return _userAvatar;
- }
- - (void)queryUserInfoWithUserId:(NSString *)userId {
- [KSNetworkingManager imUserFriendQueryDetail:KS_POST userId:userId success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *result = [dic dictionaryValueForKey:@"data"];
- if (self) {
- self.nameLabel.text = [result stringValueForKey:@"friendNickname"];
- [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[[result stringValueForKey:@"friendAvatar"] getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- }
- else {
- NSLog(@"-delloc------");
- }
- }
- else {
- if (self) {
- self.nameLabel.text = @"连麦用户";
- }
- }
- } faliure:^(NSError * _Nonnull error) {
- if (self) {
- self.nameLabel.text = @"连麦用户";
- }
- }];
- }
- @end
- @implementation SeatContentView
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.backgroundColor = [UIColor clearColor];
- }
- return self;
- }
- - (void)refreshSeatUI {
- [self removeAllSubviews:self];
- CGFloat space = 10;
- CGFloat width = 54;
- CGFloat height = 70;
- NSMutableArray *seatArray = [self.seatMemberArray mutableCopy];
- for (NSInteger index = 0; index < seatArray.count; index++) {
- NSString *userId = seatArray[index];
- CGRect frame = CGRectMake(space + index * (width + space), space, width, height);
- SeatMemberView *memberView = [[SeatMemberView alloc] initViewWithFrame:frame useId:userId];
- [self addSubview:memberView];
- }
- }
- - (void)removeAllSubviews:(UIView *)view {
- while (view.subviews.count) {
- [view.subviews.lastObject removeFromSuperview];
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|