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