| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //
- // MOSuperNumView.m
- // MiMoLive
- //
- // Created by SuperC on 2024/8/6.
- //
- #import "MOSuperNumView.h"
- @interface MOSuperNumView ()
- @property (weak, nonatomic) IBOutlet UIStackView *theStackView;
- @end
- @implementation MOSuperNumView
- + (instancetype)moSuperNumView{
- return [[[NSBundle mainBundle] loadNibNamed:@"MOSuperNumView" owner:self options:nil] firstObject];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
- }
- - (void)toShowNewNumber{
- for (UIView *subview in self.theStackView.arrangedSubviews) {
- [self.theStackView removeArrangedSubview:subview];
- [subview removeFromSuperview];
- }
-
- NSArray *theImgViewArr = [self toGetTheNumImageViewArr];
- for (UIImageView *imgView in theImgViewArr) {
- [self.theStackView addArrangedSubview:imgView];
- }
- }
- + (CGFloat)getTheViewWidth:(NSInteger)theNum{
- NSString *numberString = [NSString stringWithFormat:@"%zd", theNum];
-
- NSUInteger length = [numberString length];
-
- // 15 * 20
- //13.0 是希望图片更紧凑一点
- //self.theStackView.spacing = -2
- CGFloat width = length * 13.0;
- if(width < 39.0){
- width = 39.0;
- }
-
- return width;
- }
- - (NSArray *)toGetTheNumImageViewArr{
- NSString *numberString = [NSString stringWithFormat:@"%zd", self.theNum];
-
- NSUInteger length = [numberString length];
-
- NSMutableArray *tempArr = [NSMutableArray array];
-
- // 3. 遍历每一位数字
- for (NSUInteger i = 0; i < length; i++) {
- // 获取每一位数字
- unichar digitChar = [numberString characterAtIndex:i];
-
- // 将字符转换为整数值
- NSInteger digit = [[NSString stringWithFormat:@"%c", digitChar] integerValue];
- NSString *imgStr = [NSString stringWithFormat:@"gift_luck_times_%zd",digit];
- UIImage *numImg = [UIImage imageNamed:imgStr];
- UIImageView *numImgView = [[UIImageView alloc] initWithImage:numImg];
- numImgView.frame = CGRectMake(0.0, 0.0, 15.0, 20.0);
- numImgView.contentMode = UIViewContentModeScaleAspectFit;
- [tempArr addObject:numImgView];
- }
-
- return [tempArr copy];
- }
- @end
|