Files
yinmeng-ios/xplan-ios/Main/Message/View/Session/XPSessionMessageGamePageControl.m
2023-08-24 17:03:32 +08:00

79 lines
2.3 KiB
Objective-C

//
// XPSessionMessageGamePageControl.m
// xplan-ios
//
// Created by duoban on 2023/8/22.
//
#import "XPSessionMessageGamePageControl.h"
@interface XPSessionMessageGamePageControl()
@property(nonatomic,strong) UIStackView *stackView;
@end
@implementation XPSessionMessageGamePageControl
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self installUI];
[self installConstraints];
}
return self;
}
-(void)installUI{
[self addSubview:self.stackView];
}
-(void)installConstraints{
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.centerX.height.equalTo(self);
}];
}
- (void)setCurPage:(NSInteger)curPage{
_curPage = curPage;
if(self.pageList.count < 2)return;
[self setItemUI];
}
-(void)setItemUI{
NSMutableArray *viewList = [NSMutableArray array];
NSInteger count = self.pageList.count - self.stackView.subviews.count;
if(self.pageList.count == 0)return;
for (int i = 0; i < self.pageList.count; i ++) {
UIView *view;
if(i < count){
view = [UIView new];
view.tag = 100 + i;
[viewList addObject:view];
}
view.layer.cornerRadius = kGetScaleWidth(4)/2;
view.layer.masksToBounds = YES;
}
[viewList addObjectsFromArray:self.stackView.subviews];
for (int i = 0; i < viewList.count; i++) {
UIView *view = viewList[i];
if(view.superview){
[view removeFromSuperview];
}
view.backgroundColor = self.curPage == i ? UIColorFromRGB(0xFFDA24):UIColorFromRGB(0xCED1DB);
CGFloat width = self.curPage == i ? kGetScaleWidth(8):kGetScaleWidth(4);
[self.stackView addArrangedSubview:view];
[view mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(width);
make.height.mas_equalTo(kGetScaleWidth(4));
}];
}
}
#pragma mark - 懒加载
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentCenter;
_stackView.spacing = kGetScaleWidth(4);
}
return _stackView;
}
@end