XYScrollNumberImageView.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // XYScrollNumberImageView.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/11/29.
  6. //
  7. #import "XYScrollNumberImageView.h"
  8. @implementation XYScrollNumberImageView
  9. - (instancetype)initWitImageSize:(CGSize)imageSize
  10. {
  11. self = [super init];
  12. if (self) {
  13. [self setupUIImageSize:imageSize];
  14. }
  15. return self;
  16. }
  17. - (void)setupUIImageSize:(CGSize)imageSize {
  18. // 图片的排布是01234567890
  19. // 总共11张图片
  20. // 单张图片的高度和宽度
  21. NSArray *images = @[@"xy_gift_num_0", @"xy_gift_num_1", @"xy_gift_num_2", @"xy_gift_num_3", @"xy_gift_num_4", @"xy_gift_num_5", @"xy_gift_num_6", @"xy_gift_num_7", @"xy_gift_num_8", @"xy_gift_num_9",
  22. @"xy_gift_num_0",];
  23. UIImageView *tempImageView = nil;
  24. for (NSInteger i = 0; i < images.count; i++) {
  25. UIImageView *imageView = [UIImageView new];
  26. imageView.image = ImageNamed(images[i]);
  27. [self addSubview:imageView];
  28. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.size.equalTo(@(imageSize));
  30. make.centerX.equalTo(self);
  31. if (tempImageView) {
  32. make.top.equalTo(tempImageView.mas_bottom);
  33. }else {
  34. make.top.equalTo(self);
  35. }
  36. }];
  37. tempImageView = imageView;
  38. }
  39. }
  40. - (void)changeToNumber:(NSInteger)number lineCount:(NSInteger)lineCount {
  41. CGFloat originX = self.frame.origin.x;
  42. CGFloat floatNumber = number;
  43. CGFloat y = - ((CGFloat)floatNumber / lineCount) * self.f_heigh;
  44. self.frame = CGRectMake(originX, y, self.f_width, self.f_heigh);
  45. }
  46. @end