SignHeaderCollectReusView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //
  2. // SignHeaderCollectReusView.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/29.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "SignHeaderCollectReusView.h"
  9. @interface SignHeaderCollectReusView ()
  10. @property(nonatomic, strong) UIImageView *bgImageView;
  11. @property(nonatomic, strong) UIImageView *iconImageView;
  12. @property (nonatomic,strong)UILabel *titleLabel;
  13. @property(nonatomic, strong) UIView *bgView;
  14. @property (nonatomic,strong)UILabel *tipLabel;
  15. @end
  16. static NSString *const image_name_bg = @"签到页背景";
  17. static NSString *const image_name = @"插画";
  18. static NSString *const image_name_btn = @"数字显示";
  19. @implementation SignHeaderCollectReusView
  20. - (instancetype)initWithFrame:(CGRect)frame
  21. {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. [self initUI];
  25. }
  26. return self;
  27. }
  28. - (void)initUI {
  29. _bgImageView = ({
  30. UIImageView * iv = [[UIImageView alloc] init];
  31. iv.image = [UIImage imageNamed:image_name_bg];
  32. iv;
  33. });
  34. _titleLabel = ({
  35. UILabel * label = [[UILabel alloc]init];
  36. label.textColor = kWhiteColor;
  37. label.font = [UIFont systemFontOfSize:13];
  38. label.text = ASLocalizedString(@"已连续签到");
  39. label;
  40. });
  41. _tipLabel = ({
  42. UILabel * label = [[UILabel alloc]init];
  43. label.textColor = kWhiteColor;
  44. label.font = [UIFont systemFontOfSize:13];
  45. label.text = ASLocalizedString(@"天");
  46. label;
  47. });
  48. _iconImageView = ({
  49. UIImageView * iv = [[UIImageView alloc] init];
  50. iv.image = [UIImage imageNamed:image_name];
  51. iv.hidden = YES;
  52. iv;
  53. });
  54. [self addSubview:_bgImageView];
  55. [_bgImageView addSubview:_titleLabel];
  56. [_bgImageView addSubview:_iconImageView];
  57. _bgView=({
  58. UIView * view = [[UIView alloc]init];
  59. view;
  60. });
  61. [_bgImageView addSubview:_bgView];
  62. }
  63. - (void)layoutSubviews {
  64. [super layoutSubviews];
  65. [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.edges.equalTo(self).insets(UIEdgeInsetsMake(8, 8, 8, 8));
  67. }];
  68. [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.bottom.mas_equalTo(-6);
  70. make.right.mas_equalTo(-37);
  71. }];
  72. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.top.mas_equalTo(40);
  74. make.left.mas_equalTo(40);
  75. }];
  76. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.equalTo(_titleLabel.mas_bottom).offset(10);
  78. make.left.mas_equalTo(40);
  79. // make.width.mas_equalTo(30*4);
  80. make.height.mas_equalTo(45);
  81. }];
  82. }
  83. - (void)setDataWithsignin_continue:(NSString *)signin_continue signin_count:(NSString *)signin_count{
  84. [_bgView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  85. if (signin_continue.intValue == 1) {
  86. UIView * lastView ;
  87. int totalCount = 3;
  88. if (signin_count.intValue > 999) {
  89. totalCount=signin_count.length;
  90. }else{
  91. signin_count = [NSString stringWithFormat:@"%03d",signin_count.intValue];
  92. }
  93. for (int i = 0; i < totalCount; i ++) {
  94. NSString *numStr=[signin_count substringWithRange:NSMakeRange(i, 1)];
  95. UIButton * numBtn = ({
  96. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  97. [btn setBackgroundImage:[UIImage imageNamed:image_name_btn] forState:UIControlStateNormal];
  98. [btn setTitle:numStr forState:UIControlStateNormal];
  99. [btn setTitleColor:[UIColor colorWithHexString:@"#CD49FF"] forState:UIControlStateNormal];
  100. btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
  101. btn;
  102. });
  103. [_bgView addSubview:numBtn];
  104. [numBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.mas_equalTo(_bgView).offset((30+7)*i);
  106. make.centerY.mas_equalTo(_bgView);
  107. }];
  108. lastView = numBtn;
  109. }
  110. [_bgView addSubview:_tipLabel];
  111. [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.bottom.mas_equalTo(lastView);
  113. make.left.mas_equalTo(37*totalCount);
  114. }];
  115. }else{
  116. UIView * lastView ;
  117. int totalCount = 3;
  118. for (int i = 0; i < totalCount; i ++) {
  119. UIButton * numBtn = ({
  120. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  121. [btn setBackgroundImage:[UIImage imageNamed:image_name_btn] forState:UIControlStateNormal];
  122. [btn setTitle:@"0" forState:UIControlStateNormal];
  123. [btn setTitleColor:[UIColor colorWithHexString:@"#CD49FF"] forState:UIControlStateNormal];
  124. btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
  125. btn;
  126. });
  127. [_bgView addSubview:numBtn];
  128. [numBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.left.mas_equalTo(_bgView).offset((30+7)*i);
  130. make.centerY.mas_equalTo(_bgView);
  131. }];
  132. lastView = numBtn;
  133. }
  134. [_bgView addSubview:_tipLabel];
  135. [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.bottom.mas_equalTo(lastView);
  137. make.left.mas_equalTo(37*totalCount);
  138. }];
  139. }
  140. }
  141. @end