显示文件进度文本时,UILabel文本闪烁

时间:2017-03-25 12:13:10

标签: ios objective-c nsstring uilabel

我在标签中显示文件传输进度。但是当fileprogress数据字符串出现时,directionstring文本根据其位置闪烁。如何阻止附加字符串的闪烁?

directionstring = @"uploaging file";
fileprogress = transferring rate EX.(25.00 MB of 50.00 MB);
message = [message stringByAppendingString:[NSString stringWithFormat:@"%@%@",fileprogress,directionstring]];
progressLabel.text = message;

1 个答案:

答案 0 :(得分:0)

我做了一个例子(用计时器来模拟进度),测试它,文本没有闪烁

@implementation ViewController
{
    IBOutlet UILabel *_progressLabel;
    NSInteger _percent;
}

- (void)showProgress
{
    _percent = 0;

    [NSTimer scheduledTimerWithTimeInterval:0.2
                                     target:self
                                   selector:@selector(updateProgress:)
                                   userInfo:nil
                                    repeats:YES];
}

- (void)updateProgress:(NSTimer *)timer {
    NSString *directionstring = @" uploading file";
    NSString *fileprogress = [NSString stringWithFormat:@"%ld of 100", (long)_percent++];
    NSString *message = [NSString stringWithFormat:@"%@%@", fileprogress, directionstring];
    _progressLabel.text = message;
}

@end