数字动画UICountingLabel运用

    UICountingLabel *countLabel = [UICountingLabel newAutoLayoutView];
    countLabel.textAlignment = NSTextAlignmentCenter;
    countLabel.font = [UIFont fontWithName:@"Arial-Black" size:38];
    countLabel.textColor = [UIColor colorWithHTMLExpression:@"#e68a45"];
    [countView addSubview:countLabel];
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(countView.mas_centerX).with.offset(34);
    }];
    countLabel.format = @"%ld";
    countLabel.positiveFormat = @"###,###,###,##0";
    //设置变化范围及动画时间
    [countLabel countFrom:0.00
                       to:countNumber
             withDuration:2.0f];
   

    UIImageView *iconImageView = [UIImageView newAutoLayoutView];
    UIImage *image = [UIImage imageNamed:iconImageName];
    iconImageView.image = image;
    [countView addSubview:iconImageView];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(countLabel.mas_leading).with.offset(-kMarginX);
        make.height.offset(kHeight);
        make.bottom.equalTo(countView.mas_bottom);
        make.width.equalTo(iconImageView.mas_height).with.multipliedBy(image.size.width/image.size.height);
    }];

    [countLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconImageView.mas_centerY);
    }];

在网上找的数字变化demo,这里效果是需要图片和文字整体居中垂直对齐。所以我在最后使countLabel updateConstraints。
效果:

IMG_3511.gif

参考链接:
http://www.open-open.com/lib/view/open1465700275644.html

你可能感兴趣的:(数字动画UICountingLabel运用)