KWScrollOffsetView.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // KWScrollOffsetView.m
  3. // westkissMob
  4. //
  5. // Created by iOS on 2022/9/6.
  6. //
  7. #import "KWScrollOffsetView.h"
  8. @interface KWScrollOffsetView ()
  9. @end
  10. @implementation KWScrollOffsetView
  11. - (void)setOffWidth:(CGFloat)offWidth {
  12. _offWidth = offWidth;
  13. if (self.offsetV.superview != nil) {
  14. [self.offsetV mas_updateConstraints:^(MASConstraintMaker *make) {
  15. make.width.equalTo([NSNumber numberWithFloat:_offWidth]);
  16. }];
  17. }
  18. }
  19. - (void)setOffset:(CGFloat)offset {
  20. CGFloat newoff = offset < 0 ? 0 : offset;
  21. newoff = offset > 1 ? 1 : offset;
  22. _offset = newoff;
  23. if (self.offsetV.superview != nil && self.offsetV.superview.superview != nil) {
  24. CGFloat scrollMax = self.frame.size.width-self.offWidth;
  25. CGFloat newOff = scrollMax*newoff;
  26. [self.offsetV mas_updateConstraints:^(MASConstraintMaker *make) {
  27. make.left.equalTo([NSNumber numberWithFloat:newOff]);
  28. }];
  29. }
  30. }
  31. - (instancetype)initWithFrame:(CGRect)frame {
  32. self = [super initWithFrame:frame];
  33. if (self) {
  34. [self configSubV];
  35. }
  36. return self;
  37. }
  38. -(void)configSubV {
  39. self.offsetV = [[UIView alloc] init];
  40. self.offsetV.backgroundColor = [UIColor colorWithHexString:@"#707070"];
  41. self.backgroundColor = [UIColor colorWithHexString:@"#C5C5C5"];
  42. [self addSubview:self.offsetV];
  43. [self.offsetV mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.bottom.equalTo(self);
  45. make.left.equalTo(@0);
  46. make.width.equalTo([NSNumber numberWithFloat:54]);
  47. }];
  48. }
  49. @end