12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // XYScrollNumberImageView.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/11/29.
- //
- #import "XYScrollNumberImageView.h"
- @implementation XYScrollNumberImageView
- - (instancetype)initWitImageSize:(CGSize)imageSize
- {
- self = [super init];
- if (self) {
- [self setupUIImageSize:imageSize];
- }
- return self;
- }
- - (void)setupUIImageSize:(CGSize)imageSize {
- // 图片的排布是01234567890
- // 总共11张图片
- // 单张图片的高度和宽度
- 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",
- @"xy_gift_num_0",];
- UIImageView *tempImageView = nil;
- for (NSInteger i = 0; i < images.count; i++) {
- UIImageView *imageView = [UIImageView new];
- imageView.image = ImageNamed(images[i]);
- [self addSubview:imageView];
- [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.equalTo(@(imageSize));
- make.centerX.equalTo(self);
- if (tempImageView) {
- make.top.equalTo(tempImageView.mas_bottom);
- }else {
- make.top.equalTo(self);
- }
- }];
- tempImageView = imageView;
- }
- }
- - (void)changeToNumber:(NSInteger)number lineCount:(NSInteger)lineCount {
- CGFloat originX = self.frame.origin.x;
- CGFloat floatNumber = number;
- CGFloat y = - ((CGFloat)floatNumber / lineCount) * self.f_heigh;
- self.frame = CGRectMake(originX, y, self.f_width, self.f_heigh);
- }
- @end
|