123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // XFStepView.m
- // SCPay
- //
- // Created by weihongfang on 2017/6/26.
- // Copyright © 2017年 weihongfang. All rights reserved.
- //
- #import "XFStepView.h"
- #import "JXMyModel.h"
- @interface XFStepView()
- @property (nonatomic, strong)UIView *lineUndo;
- @property (nonatomic, strong)UIView *lineDone;
- @property (nonatomic, retain)NSMutableArray *cricleMarks;
- @property (nonatomic, retain)NSMutableArray *titleLabels;
- @property (nonatomic, strong)UILabel *lblIndicator;
- @end
- @implementation XFStepView
- - (instancetype)initWithFrame:(CGRect)frame Titles:(nonnull NSArray *)titles{
- if ([super initWithFrame:frame]){
- _stepIndex = 0;
- _titles = titles;
-
- _lineUndo = [[UIView alloc]init];
- _lineUndo.backgroundColor = [UIColor colorWithRed:231/255.0 green:228/255.0 blue:223/255.0 alpha:1.0];
- [self addSubview:_lineUndo];
-
- _lineDone = [[UIView alloc]init];
- _lineDone.backgroundColor = [UIColor redColor];
- [self addSubview:_lineDone];
-
- for (vipDetailModel *title in _titles){
- UIButton *label = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 60, 30)];
- //label.backgroundColor =[UIColor colorWithRed:228/255.0 green:226/255.0 blue:223/255.0 alpha:1];
- label.titleLabel.font=[UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
- label.layer.cornerRadius = 5;
- label.layer.masksToBounds = YES;
- [label setTitle:[NSString stringWithFormat:@"Lv%@",title.grade] forState:UIControlStateNormal];
- [label setBackgroundImage:[UIImage imageNamed:@"组39"] forState:UIControlStateNormal];
- [label setBackgroundImage:[UIImage imageNamed:@"组23"] forState:UIControlStateSelected];
- [self addSubview:label];
- [self.cricleMarks addObject:label];
- }
- }
- return self;
- }
- #pragma mark - method
- - (void)layoutSubviews{
- NSInteger perWidth = self.frame.size.width / self.titles.count;
-
- _lineUndo.frame = CGRectMake(0, 0, self.frame.size.width - perWidth, 3);
- _lineUndo.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 4+10);
-
- CGFloat startX = _lineUndo.frame.origin.x;
-
- for (int i = 0; i < _titles.count; i++){
- UIView *cricle = [_cricleMarks objectAtIndex:i];
- if (cricle != nil){
- cricle.center = CGPointMake(i * perWidth + startX, _lineUndo.center.y);
- }
- }
- self.stepIndex = _stepIndex;
- }
- - (NSMutableArray *)cricleMarks{
- if (_cricleMarks == nil){
- _cricleMarks = [NSMutableArray arrayWithCapacity:self.titles.count];
- }
- return _cricleMarks;
- }
- #pragma mark - public method
- - (void)setStepIndex:(int)stepIndex {
-
- if (stepIndex >= 0 && stepIndex < self.titles.count){
- _stepIndex = stepIndex;
-
- CGFloat perWidth = self.frame.size.width / _titles.count;
- _lineDone.frame = CGRectMake(_lineUndo.frame.origin.x, _lineUndo.frame.origin.y, perWidth * _stepIndex, _lineUndo.frame.size.height);
-
- for (int i = 0; i < _titles.count; i++){
- UIButton *cricle = [_cricleMarks objectAtIndex:i];
- if (cricle != nil){
- if (i <= _stepIndex){
- cricle.selected = YES;
- // [label setBackgroundImage:[UIImage imageNamed:@"组23"] forState:UIControlStateSelected];
- // cricle.backgroundColor = TINTCOLOR;
- }else{
- cricle.selected = NO;
- //cricle.backgroundColor = [UIColor lightGrayColor];
- }
- }
- }
- }
- }
- - (void)setStepIndex:(int)stepIndex Animation:(BOOL)animation
- {
- if (stepIndex >= 0 && stepIndex < self.titles.count){
- if (animation){
- [UIView animateWithDuration:0.5 animations:^{
- self.stepIndex = stepIndex;
- }];
- }else{
- self.stepIndex = stepIndex;
- }
- }
- }
- @end
|