123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // 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) 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(UIDKey)]) { // 自己
- UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seat_mine"]];
- [self addSubview:bgImage];
- [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.mas_centerX);
- make.top.mas_equalTo(self.mas_top);
- make.width.height.mas_equalTo(54);
- }];
- 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(bgImage.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(6);
- make.right.mas_equalTo(bgView.mas_right).offset(-6);
- }];
-
-
- self.nameLabel.font = [UIFont systemFontOfSize:9.0f weight:UIFontWeightMedium];
- self.nameLabel.text = [NSString returnNoNullStringWithString:[RCIMClient sharedRCIMClient].currentUserInfo.name];
-
- }
- else { // 其他人
- UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seat_other"]];
- [self addSubview:bgImage];
- [bgImage 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(bgImage.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;
- }
- - (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"];
- self.nameLabel.text = [result stringValueForKey:@"friendNickname"];
- }
- else {
- self.nameLabel.text = @"连麦用户";
- }
- } faliure:^(NSError * _Nonnull error) {
- self.nameLabel.text = @"连麦用户";
- }];
- }
- @end
- @implementation SeatContentView
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.backgroundColor = [UIColor clearColor];
- }
- return self;
- }
- - (void)refreshSeatUI {
- [self removeAllSubViews];
- CGFloat space = 10;
- CGFloat width = 54;
- CGFloat height = 70;
- for (NSInteger index = 0; index < self.seatMemberArray.count; index++) {
- NSString *userId = self.seatMemberArray[index];
- CGRect frame = CGRectMake(space + index * (width + space), space, width, height);
- SeatMemberView *memberView = [[SeatMemberView alloc] initViewWithFrame:frame useId:userId];
- [self addSubview:memberView];
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|