SellyCloudSDK_demo/Example/SellyCloudSDK/Live/SCLiveItemContainerView.m

58 lines
1.4 KiB
Objective-C

//
// SCLiveItemContainerView.m
// SellyCloudSDK_Example
//
// Created by Caleb on 21/7/25.
// Copyright © 2025 Caleb. All rights reserved.
//
#import "SCLiveItemContainerView.h"
#import "SCLiveItemView.h"
@interface SCLiveItemContainerView ()
@property (nonatomic, strong)NSMutableArray<SCLiveItemView *> *itemViews;
@end
@implementation SCLiveItemContainerView
- (instancetype)init
{
self = [super init];
if (self) {
self.backgroundColor = UIColor.cyanColor;
}
return self;
}
- (void)setModels:(NSArray<SCLiveItemModel *> *)models {
_models = models;
[self.itemViews enumerateObjectsUsingBlock:^(SCLiveItemView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj removeFromSuperview];
}];
[self.itemViews removeAllObjects];
for (NSInteger i = 0; i<models.count; i++) {
SCLiveItemView *itemView = SCLiveItemView.new;
itemView.model = models[i];
[self.itemViews addObject:itemView];
[self addSubview:itemView];
}
[self.itemViews mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:80 leadSpacing:15 tailSpacing:15];
[self.itemViews mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.offset(80);
make.centerY.offset(0);
}];
}
- (NSMutableArray<SCLiveItemView *> *)itemViews {
if (!_itemViews) {
_itemViews = NSMutableArray.array;
}
return _itemViews;
}
@end