OGeek|极客世界-中国程序员成长平台

标题: ios - 在标签中显示百分比 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:19
标题: ios - 在标签中显示百分比

我使用代码来显示从 1% 到 100% 的文件下载进度。

if( downloadTask == _downloadTask26){


        _progress26 = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
        _total26 = [[NSNumber numberWithInteger:totalBytesExpectedToWrite] floatValue];

    }

    if( downloadTask == _downloadTask27){


        _progress27 = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
        _total27 = [[NSNumber numberWithInteger:totalBytesExpectedToWrite] floatValue];

    }

        float progress = _progress26 + _progress27;
        float total = _total26 + _total27;

        NSString *percentage = [NSString stringWithFormat"%.f%%", ((progress / total) * 100)];
        (NSLog (percentage, @"%.f%%"));
        if (!_label3) {

                _label3 = [[UILabel alloc] initWithFrame:CGRectMake(200.43, 158.84, 42, 19)];

                _label3.numberOfLines = 1;
                _label3.baselineAdjustment = UIBaselineAdjustmentAlignBaselines;
                _label3.adjustsFontSizeToFitWidth = YES;
                _label3.minimumScaleFactor = 10.0f/12.0f;
                _label3.clipsToBounds = YES;
                _label3.backgroundColor = [UIColor clearColor];
                _label3.textColor = [UIColor whiteColor];
                _label3.textAlignment = NSTextAlignmentCenter;

                [_scroller addSubview:_label3];
            }
        }

        _label3.text = percentage;
        if ([_label3.text  isEqual: @"100%"]) {
        }

但文件下载时,百分比不按升序显示。百分比以不同的顺序显示,如下面的视频所示。我该如何解决?

视频 https://drive.google.com/file/d/0B0EJbcHq3ZALUVRzanJ6SndscWc/view



Best Answer-推荐答案


可能是由于下载任务条件检查它正在下载Task26或27将日志放在这两个条件中并检查下载和总大小。总任务可能会发生变化。

关于ios - 在标签中显示百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39061294/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4