123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // BuyProgressView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/9.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "BuyProgressView.h"
- #define KProgressBorderWidth 2.0f
- #define KProgressPadding 1.0f
- #define KProgressColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1]
- @interface BuyProgressView()
- @property (nonatomic, weak) UIView *tView;
- @property (nonatomic, strong) UILabel *progressLabel;
- @property (nonatomic, strong) UILabel *countLabel;
- @property (nonatomic, strong) UILabel *finishLabel;
- @end
- @implementation BuyProgressView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- if (self = [super initWithFrame:frame]) {
- //边框
- UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(104), Fitsize(14))];
- borderView.layer.cornerRadius = Fitsize(7);
- borderView.layer.masksToBounds = YES;
- borderView.backgroundColor = [UIColor YHColorWithHex:0xFF5000 alpha:0.4];
- [self addSubview:borderView];
-
- //进度
- UIView *tView = [[UIView alloc] init];
- tView.backgroundColor = [UIColor YHColorWithHex:0xFF5000];
- tView.layer.cornerRadius = Fitsize(7);
- tView.layer.masksToBounds = YES;
- [self addSubview:tView];
- self.tView = tView;
-
- self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, borderView.height)];
- self.progressLabel.textColor = [UIColor whiteColor];
- self.progressLabel.textAlignment = NSTextAlignmentRight;
- self.progressLabel.font = [UIFont systemFontOfSize:9];
- [self addSubview:self.progressLabel];
- self.progressLabel.right = borderView.width-10;
-
- self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, borderView.width-30, borderView.height)];
- self.countLabel.font = [UIFont systemFontOfSize:9];
- self.countLabel.textColor = [UIColor whiteColor];
- [self addSubview:self.countLabel];
-
- self.finishLabel = [[UILabel alloc] initWithFrame:borderView.bounds];
- self.finishLabel.font = [UIFont systemFontOfSize:11];
- self.finishLabel.textColor = [UIColor whiteColor];
- self.finishLabel.textAlignment = NSTextAlignmentCenter;
- self.finishLabel.hidden = YES;
- self.finishLabel.text = @"已售馨";
- [self addSubview:self.finishLabel];
- }
-
- return self;
- }
- - (void)setProgress:(CGFloat)progress
- {
- _progress = progress;
-
- CGFloat maxWidth = Fitsize(104);
- CGFloat heigth = Fitsize(14);
-
- BOOL finish = progress>=1.0?YES:NO;
-
- if (finish) {
- self.finishLabel.hidden = NO;
- self.countLabel.hidden = YES;
- }else {
- self.progressLabel.text = [NSString stringWithFormat:@"%.f%@",progress*100,@"%"];
- self.finishLabel.hidden = YES;
- self.countLabel.hidden = NO;
- }
-
- _tView.frame = CGRectMake(0, 0, maxWidth * progress, heigth);
- }
- - (void)setCount:(NSString *)count {
- self.countLabel.text = [NSString stringWithFormat:@"已售%@件",count];
- }
- @end
|