Nenhuma Descrição

FKGroupStepCell.m 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // FKGroupStepCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/10/7.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKGroupStepCell.h"
  9. #define kNumLabelTagBase 1000
  10. #define kStepLabelTagBase 2000
  11. #define kAreaTagBase 500
  12. #define VIP_PROTOCOL_URL ([NSString stringWithFormat:@"%@/link-site/mobile/fightGroups/explain.html", [[FKServerUtil sharedInstance] apiServer]])
  13. @interface FKGroupStepCell ()
  14. @property (nonatomic, strong) UILabel *leftLabel;
  15. @property (nonatomic, strong) UILabel *rightLabel;
  16. @property (nonatomic, strong) UIImageView *rightArrow;
  17. @end
  18. @implementation FKGroupStepCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  20. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  21. self.selectionStyle = UITableViewCellSelectionStyleNone;
  22. [self addAllSubviews];
  23. }
  24. return self;
  25. }
  26. + (NSString *)pushExplainUrl{
  27. return VIP_PROTOCOL_URL;
  28. }
  29. - (void)addAllSubviews{
  30. UIView *area1 = [[UIView alloc]init];
  31. UIView *area2 = [[UIView alloc]init];
  32. UIView *area3 = [[UIView alloc]init];
  33. UIView *area4 = [[UIView alloc]init];
  34. [self.contentView addSubview:self.leftLabel];
  35. [self.contentView addSubview:self.rightLabel];
  36. [self.contentView addSubview:self.rightArrow];
  37. [self.contentView addSubview:area1];
  38. [self.contentView addSubview:area2];
  39. [self.contentView addSubview:area3];
  40. [self.contentView addSubview:area4];
  41. [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.equalTo(self.contentView).offset(10);
  43. make.top.equalTo(self.contentView).offset(10);
  44. }];
  45. [self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.centerY.equalTo(self.leftLabel);
  47. make.right.equalTo(self.contentView).offset(-12);
  48. }];
  49. [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerY.equalTo(self.leftLabel);
  51. make.right.equalTo(self.rightArrow.mas_left).offset(-6);
  52. }];
  53. [area1 mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.leftLabel.mas_bottom);
  55. make.left.bottom.equalTo(self.contentView);
  56. make.width.equalTo(self.contentView).multipliedBy(0.25);
  57. }];
  58. [area2 mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.equalTo(area1.mas_right);
  60. make.top.bottom.equalTo(area1);
  61. make.width.equalTo(self.contentView).multipliedBy(0.25);
  62. }];
  63. [area3 mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.equalTo(area2.mas_right);
  65. make.top.bottom.equalTo(area1);
  66. make.width.equalTo(self.contentView).multipliedBy(0.25);
  67. }];
  68. [area4 mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.equalTo(area3.mas_right);
  70. make.top.bottom.equalTo(area1);
  71. make.right.equalTo(self.contentView);
  72. }];
  73. [self configArea:area1 stepNum:kGroupStepSelect title:@"选择心仪\n的商品"];
  74. [self configArea:area2 stepNum:kGroupStepPay title:@"支付开团\n或参团"];
  75. [self configArea:area3 stepNum:kGroupStepInvite title:@"邀请好友\n参团支付"];
  76. [self configArea:area4 stepNum:kGroupStepFinish title:@"达到人数\n团购成功"];
  77. }
  78. - (void)configArea:(UIView *)area stepNum:(kGroupStep)step title:(NSString *)title{
  79. area.tag = kAreaTagBase + step;
  80. UIImageView *circle = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xuCircle"]];
  81. UILabel *numLabel = [self createNumLabelWithText:[NSString stringWithFormat:@"%lu", ((unsigned long)step + 1)] tag:kNumLabelTagBase + step];
  82. UILabel *titleLabel = [self createLabelWithTitle:title tag:kStepLabelTagBase + step];
  83. [area addSubview:circle];
  84. [area addSubview:numLabel];
  85. [area addSubview:titleLabel];
  86. // UI布局适配
  87. CGFloat margin = 10;
  88. CGFloat titleMargin = 8;
  89. if (step != kGroupStepSelect && (IS_IPHONE_4 || IS_IPHONE_5)) margin = 5;
  90. if (IS_IPHONE_4 || IS_IPHONE_5) titleMargin = 4;
  91. [circle mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.equalTo(area).offset(margin);
  93. make.centerY.equalTo(area);
  94. }];
  95. [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.center.equalTo(circle);
  97. make.width.height.mas_equalTo(20);
  98. }];
  99. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.left.equalTo(circle.mas_right).offset(titleMargin);
  101. make.centerY.equalTo(circle);
  102. }];
  103. }
  104. - (UILabel *)createNumLabelWithText:(NSString *)text tag:(NSUInteger)tag{
  105. UILabel *label = [[UILabel alloc]init];
  106. label.textColor = UIColorFromRGB(0x666666);
  107. label.layer.cornerRadius = 10;
  108. label.layer.masksToBounds = YES;
  109. label.textAlignment = NSTextAlignmentCenter;
  110. label.font = [UIFont boldSystemFontOfSize:12];
  111. label.tag = tag;
  112. label.text = text;
  113. return label;
  114. }
  115. - (UILabel *)createLabelWithTitle:(NSString *)title tag:(NSUInteger)tag{
  116. UILabel *label = [[UILabel alloc]init];
  117. label.text = title;
  118. label.tag = tag;
  119. label.font = [UIFont systemFontOfSize:11];
  120. label.textColor = UIColorFromRGB(0x666666);
  121. label.numberOfLines = 0;
  122. return label;
  123. }
  124. - (void)setStep:(kGroupStep)step{
  125. UIView *area = [self.contentView viewWithTag:kAreaTagBase + step];
  126. UILabel *numLabel = (UILabel *)[area viewWithTag:kNumLabelTagBase + step];
  127. UILabel *titleLabel = (UILabel *)[area viewWithTag:kStepLabelTagBase + step];
  128. if (numLabel) {
  129. numLabel.backgroundColor = UIColorFromRGB(0x49d0bb);
  130. numLabel.textColor = [UIColor whiteColor];
  131. }
  132. if (titleLabel){
  133. titleLabel.textColor = UIColorFromRGB(0x49d0bb);
  134. }
  135. }
  136. - (UILabel *)leftLabel{
  137. if (_leftLabel == nil) {
  138. _leftLabel = [[UILabel alloc]init];
  139. _leftLabel.textColor = UIColorFromRGB(0x999999);
  140. _leftLabel.font = [UIFont systemFontOfSize:11];
  141. _leftLabel.text = @"拼团玩法";
  142. }
  143. return _leftLabel;
  144. }
  145. - (UILabel *)rightLabel{
  146. if (_rightLabel == nil) {
  147. _rightLabel = [[UILabel alloc]init];
  148. _rightLabel.textColor = UIColorFromRGB(0x333333);
  149. _rightLabel.font = [UIFont systemFontOfSize:12];
  150. _rightLabel.text = @"活动详情";
  151. }
  152. return _rightLabel;
  153. }
  154. - (UIImageView *)rightArrow{
  155. if (_rightArrow == nil) {
  156. _rightArrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"groupRightArrow_small"]];
  157. }
  158. return _rightArrow;
  159. }
  160. @end