2017-03-25 33 views
1

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

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

你可能会重新绘制的标签! @psk –

回答

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