XFStepView.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // XFStepView.m
  3. // SCPay
  4. //
  5. // Created by weihongfang on 2017/6/26.
  6. // Copyright © 2017年 weihongfang. All rights reserved.
  7. //
  8. #import "XFStepView.h"
  9. #import "JXMyModel.h"
  10. @interface XFStepView()
  11. @property (nonatomic, strong)UIView *lineUndo;
  12. @property (nonatomic, strong)UIView *lineDone;
  13. @property (nonatomic, retain)NSMutableArray *cricleMarks;
  14. @property (nonatomic, retain)NSMutableArray *titleLabels;
  15. @property (nonatomic, strong)UILabel *lblIndicator;
  16. @end
  17. @implementation XFStepView
  18. - (instancetype)initWithFrame:(CGRect)frame Titles:(nonnull NSArray *)titles{
  19. if ([super initWithFrame:frame]){
  20. _stepIndex = 0;
  21. _titles = titles;
  22. _lineUndo = [[UIView alloc]init];
  23. _lineUndo.backgroundColor = [UIColor colorWithRed:231/255.0 green:228/255.0 blue:223/255.0 alpha:1.0];
  24. [self addSubview:_lineUndo];
  25. _lineDone = [[UIView alloc]init];
  26. _lineDone.backgroundColor = [UIColor redColor];
  27. [self addSubview:_lineDone];
  28. for (vipDetailModel *title in _titles){
  29. UIButton *label = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 60, 30)];
  30. //label.backgroundColor =[UIColor colorWithRed:228/255.0 green:226/255.0 blue:223/255.0 alpha:1];
  31. label.titleLabel.font=[UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
  32. label.layer.cornerRadius = 5;
  33. label.layer.masksToBounds = YES;
  34. [label setTitle:[NSString stringWithFormat:@"Lv%@",title.grade] forState:UIControlStateNormal];
  35. [label setBackgroundImage:[UIImage imageNamed:@"组39"] forState:UIControlStateNormal];
  36. [label setBackgroundImage:[UIImage imageNamed:@"组23"] forState:UIControlStateSelected];
  37. [self addSubview:label];
  38. [self.cricleMarks addObject:label];
  39. }
  40. }
  41. return self;
  42. }
  43. #pragma mark - method
  44. - (void)layoutSubviews{
  45. NSInteger perWidth = self.frame.size.width / self.titles.count;
  46. _lineUndo.frame = CGRectMake(0, 0, self.frame.size.width - perWidth, 3);
  47. _lineUndo.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 4+10);
  48. CGFloat startX = _lineUndo.frame.origin.x;
  49. for (int i = 0; i < _titles.count; i++){
  50. UIView *cricle = [_cricleMarks objectAtIndex:i];
  51. if (cricle != nil){
  52. cricle.center = CGPointMake(i * perWidth + startX, _lineUndo.center.y);
  53. }
  54. }
  55. self.stepIndex = _stepIndex;
  56. }
  57. - (NSMutableArray *)cricleMarks{
  58. if (_cricleMarks == nil){
  59. _cricleMarks = [NSMutableArray arrayWithCapacity:self.titles.count];
  60. }
  61. return _cricleMarks;
  62. }
  63. #pragma mark - public method
  64. - (void)setStepIndex:(int)stepIndex {
  65. if (stepIndex >= 0 && stepIndex < self.titles.count){
  66. _stepIndex = stepIndex;
  67. CGFloat perWidth = self.frame.size.width / _titles.count;
  68. _lineDone.frame = CGRectMake(_lineUndo.frame.origin.x, _lineUndo.frame.origin.y, perWidth * _stepIndex, _lineUndo.frame.size.height);
  69. for (int i = 0; i < _titles.count; i++){
  70. UIButton *cricle = [_cricleMarks objectAtIndex:i];
  71. if (cricle != nil){
  72. if (i <= _stepIndex){
  73. cricle.selected = YES;
  74. // [label setBackgroundImage:[UIImage imageNamed:@"组23"] forState:UIControlStateSelected];
  75. // cricle.backgroundColor = TINTCOLOR;
  76. }else{
  77. cricle.selected = NO;
  78. //cricle.backgroundColor = [UIColor lightGrayColor];
  79. }
  80. }
  81. }
  82. }
  83. }
  84. - (void)setStepIndex:(int)stepIndex Animation:(BOOL)animation
  85. {
  86. if (stepIndex >= 0 && stepIndex < self.titles.count){
  87. if (animation){
  88. [UIView animateWithDuration:0.5 animations:^{
  89. self.stepIndex = stepIndex;
  90. }];
  91. }else{
  92. self.stepIndex = stepIndex;
  93. }
  94. }
  95. }
  96. @end