[Objective-C] 纯文本查看 复制代码
-(instancetype)initWithFrame:(CGRect)frame withStartNum:(CGFloat)startNum withEndNum:(CGFloat)endNum withSignNum:(CGFloat)signNum withTime:(CGFloat)time{[/align]
[align=left]if (self = [super initWithFrame:frame]) {[/align]
[align=left]self.startNum = startNum;[/align]
[align=left]self.endNum = endNum;[/align]
[align=left]self.signNum = signNum;[/align]
[align=left]if(time == 0){[/align]
[align=left]self.time = 0.1;[/align]
[align=left]}else{[/align]
[align=left]self.time = time;[/align]
[align=left]}[/align]
[align=left][self setUpSubViews];[/align]
[align=left]}[/align]
[align=left]return self;[/align]
[align=left]}[/align]
[align=left]- (void)setUpSubViews[/align]
[align=left]{[/align]
[align=left]UIView *backView = [[UIView alloc] init];[/align]
[align=left]backView.backgroundColor =BoomViewColor;[/align]
[align=left]backView.layer.cornerRadius = CornerRadius;[/align]
[align=left]backView.layer.masksToBounds = YES;[/align]
[align=left][self addSubview:backView];[/align]
[align=left]self.backView = backView;[/align]
[align=left]UIView *fontView = [[UIView alloc] init];[/align]
[align=left]fontView.backgroundColor = UpViewColor;[/align]
[align=left]fontView.layer.cornerRadius = CornerRadius;[/align]
[align=left]fontView.layer.masksToBounds = YES;[/align]
[align=left][self addSubview:fontView];[/align]
[align=left]self.fontView = fontView;[/align]
[align=left]}[/align]
[align=left]-(void)progressViewStart{[/align]
[align=left]if (self.timer == nil) {[/align]
[align=left]dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{[/align]
[align=left]self.timer = [NSTimer scheduledTimerWithTimeInterval:self.time target:self selector:@selector(changeProgressViewFrame:) userInfo:nil repeats:YES];[/align]
[align=left][[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];[/align]
[align=left]});[/align]
[align=left]}[/align]
[align=left]}[/align]
[align=left]-(void)changeProgressViewFrame:(NSTimer *)timer{[/align]
[align=left]//位置计算[/align]
[align=left]CGFloat signProgress = (self.signNum - self.startNum) / (self.endNum - self.startNum);[/align]
[align=left]NSLog(@"==>>>%f",self.progress);[/align]
[align=left]if (self.progress >= signProgress){[/align]
[align=left][self.timer invalidate];[/align]
[align=left]self.timer = nil;[/align]
[align=left]return;[/align]
[align=left]}[/align]
[align=left]self.progress += 0.01;[/align]
[align=left][self setNeedsLayout];[/align]
[align=left]}[/align]
[align=left]-(void)layoutSubviews{[/align]
[align=left][super layoutSubviews];[/align]
[align=left]NSLog(@"==>>>%f",self.progress);[/align]
[align=left]self.backView.frame = self.bounds;[/align]
[align=left]self.fontView.frame = self.bounds;[/align]
[align=left]self.fontView.width = self.width * self.progress;[/align]
[align=left]}