【问题标题】:UILabel text blinking when showing file progress text显示文件进度文本时 UILabel 文本闪烁
【发布时间】:2017-08-18 09:01:56
【问题描述】:
我在标签中显示文件传输进度。但是当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;
【问题讨论】:
标签:
ios
objective-c
nsstring
uilabel
【解决方案1】:
我做了一个例子(用计时器来模拟进度),测试一下,文字不闪烁
@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