// // KWScrollOffsetView.m // westkissMob // // Created by iOS on 2022/9/6. // #import "KWScrollOffsetView.h" @interface KWScrollOffsetView () @end @implementation KWScrollOffsetView - (void)setOffWidth:(CGFloat)offWidth { _offWidth = offWidth; if (self.offsetV.superview != nil) { [self.offsetV mas_updateConstraints:^(MASConstraintMaker *make) { make.width.equalTo([NSNumber numberWithFloat:_offWidth]); }]; } } - (void)setOffset:(CGFloat)offset { CGFloat newoff = offset < 0 ? 0 : offset; newoff = offset > 1 ? 1 : offset; _offset = newoff; if (self.offsetV.superview != nil && self.offsetV.superview.superview != nil) { CGFloat scrollMax = self.frame.size.width-self.offWidth; CGFloat newOff = scrollMax*newoff; [self.offsetV mas_updateConstraints:^(MASConstraintMaker *make) { make.left.equalTo([NSNumber numberWithFloat:newOff]); }]; } } - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self configSubV]; } return self; } -(void)configSubV { self.offsetV = [[UIView alloc] init]; self.offsetV.backgroundColor = [UIColor colorWithHexString:@"#707070"]; self.backgroundColor = [UIColor colorWithHexString:@"#C5C5C5"]; [self addSubview:self.offsetV]; [self.offsetV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.equalTo(self); make.left.equalTo(@0); make.width.equalTo([NSNumber numberWithFloat:54]); }]; } @end