Files
peko-ios/YuMi/Modules/YMRoom/View/MSRoomOnLineView/MSRoomOnLineView.m
2024-05-23 18:16:04 +08:00

167 lines
5.4 KiB
Objective-C

//
// MSRoomOnLineView.m
// YuMi
//
// Created by duoban on 2024/5/20.
//
#import "MSRoomOnLineView.h"
#import "XPMessageRemoteExtModel.h"
#import "MSRoomOnLineAvatarView.h"
@interface MSRoomOnLineView()
///在线数量背景
@property(nonatomic,strong) UIView *countBgView;
///在线数量logo
@property(nonatomic,strong) UIImageView *countIconView;
///在线数量
@property(nonatomic,strong) UILabel *countView;
///头像背景
@property(nonatomic,strong) UIScrollView *onlineStackView;
@property(nonatomic,strong) UIStackView *stackView;
@end
@implementation MSRoomOnLineView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
[self addSubview:self.countBgView];
[self addSubview:self.onlineStackView];
[self.countBgView addSubview:self.countIconView];
[self.countBgView addSubview:self.countView];
[self.onlineStackView addSubview:self.stackView];
}
-(void)installConstraints{
[self.countBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(24);
make.top.equalTo(self);
make.trailing.mas_equalTo(0);
}];
[self.countIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(10);
make.top.mas_equalTo(2);
make.centerX.equalTo(self.countBgView);
}];
[self.countView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.countIconView.mas_bottom).mas_offset(0);
make.leading.trailing.equalTo(self.countBgView).inset(2);
}];
[self.onlineStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(76);
make.height.mas_equalTo(24);
make.top.leading.equalTo(self);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.onlineStackView);
}];
for (int i = 0; i < 3; i++) {
MSRoomOnLineAvatarView *avatarView = [[MSRoomOnLineAvatarView alloc]initWithFrame:CGRectZero];
avatarView.tag = 100 + i;
[self.stackView addArrangedSubview:avatarView];
avatarView.isHiddenSubView = YES;
[avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(24);
}];
}
if (isMSRTL()) {
self.onlineStackView.transform = CGAffineTransformMakeRotation(M_PI);
self.stackView.transform = CGAffineTransformMakeRotation(M_PI);
}
}
- (void)setCount:(NSString *)count{
_count = count;
_countView.text = _count;
}
- (void)setAvatarList:(NSArray *)avatarList{
_avatarList = avatarList;
if(_avatarList.count == 0)return;
MSRoomOnLineAvatarView *imageView1 = [self.stackView viewWithTag:100];
MSRoomOnLineAvatarView *imageView2 = [self.stackView viewWithTag:101];
MSRoomOnLineAvatarView *imageView3 = [self.stackView viewWithTag:102];
imageView1.isHiddenSubView = YES;
imageView2.isHiddenSubView = YES;
imageView3.isHiddenSubView = YES;
if(_avatarList.count == 1){
imageView3.isHiddenSubView = NO;
XPMessageRemoteExtModel *model3 = _avatarList[0];
imageView3.model = model3;
}else if(_avatarList.count == 2){
imageView2.isHiddenSubView = NO;
XPMessageRemoteExtModel *model2 = _avatarList[0];
imageView2.model = model2;
imageView3.isHiddenSubView = NO;
XPMessageRemoteExtModel *model3 = _avatarList[1];
imageView3.model = model3;
}else{
imageView1.isHiddenSubView = NO;
XPMessageRemoteExtModel *model1 = _avatarList[0];
imageView1.model = model1;
imageView2.isHiddenSubView = NO;
XPMessageRemoteExtModel *model2 = _avatarList[1];
imageView2.model = model2;
imageView3.isHiddenSubView = NO;
XPMessageRemoteExtModel *model3 = _avatarList[2];
imageView3.model = model3;
}
}
#pragma mark - 懒加载
- (UIView *)countBgView{
if(!_countBgView){
_countBgView = [UIView new];
_countBgView.layer.cornerRadius = 12;
_countBgView.layer.masksToBounds = YES;
_countBgView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];
}
return _countBgView;
}
- (UIImageView *)countIconView{
if(!_countIconView){
_countIconView = [UIImageView new];
_countIconView.image = kImage(@"ms_room_onLine_icon");
}
return _countIconView;
}
- (UILabel *)countView{
if(!_countView){
_countView = [UILabel labelInitWithText:@"0" font:[UIFont systemFontOfSize:9 weight:UIFontWeightBold] textColor:[UIColor whiteColor]];
_countView.textAlignment = NSTextAlignmentCenter;
}
return _countView;
}
- (UIScrollView *)onlineStackView {
if (!_onlineStackView) {
_onlineStackView = [[UIScrollView alloc] init];
_onlineStackView.scrollEnabled = NO;
}
return _onlineStackView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = 5;
}
return _stackView;
}
@end