No Description

FKCouponTableViewCell.m 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. //
  2. // CashCouponCell.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 15/6/19.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCouponTableViewCell.h"
  9. #import "FLStringHelper.h"
  10. @interface FKCouponTableViewCell ()
  11. @property (nonatomic, strong) UIView *bgView;
  12. @property (nonatomic, strong) UIView *topBanner;
  13. @property (nonatomic, strong) UIView *leftDotView;
  14. @property (nonatomic, strong) UIView *rightDotView;
  15. @property (nonatomic, strong) UIImageView *separateLine;
  16. @property (nonatomic, strong) UIImageView *bottomSpotLine;
  17. @property (nonatomic, strong) UILabel *couponNameLabel;
  18. @property (nonatomic, strong) UILabel *couponDetailLabel;
  19. @property (nonatomic, strong) UILabel *couponRuleLabel;
  20. @property (nonatomic, strong) UILabel *couponDateLabel;
  21. @property (nonatomic, strong) UIImageView *invalidBgView;
  22. @property (nonatomic, strong) UIImageView *expireImageView;
  23. @end
  24. @implementation FKCouponTableViewCell
  25. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  26. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  27. if (self) {
  28. self.contentView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  29. [self addAllSubViews];
  30. }
  31. return self;
  32. }
  33. #pragma mark -
  34. - (void)configCellWith:(FKCouponItem *)item serveTime:(NSString *)serveTime{
  35. if ([item getCouponType] != FKCouponTypeAcitivityCard) {
  36. self.couponNameLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:item.amount]];
  37. self.couponDetailLabel.text = item.typeDesc;
  38. self.couponRuleLabel.text = item.desc;
  39. self.couponDateLabel.text = item.timeDesc;
  40. }
  41. // config style
  42. if ([item.status isEqualToString:@"1"] && [item.useMark isEqualToString:@"1"]) {
  43. self.topBanner.backgroundColor = UIColorFromRGB(0xff624a);
  44. self.couponNameLabel.textColor = UIColorFromRGB(0xff624a);
  45. self.couponDetailLabel.textColor = UIColorFromRGB(0x333333);
  46. self.couponRuleLabel.textColor = UIColorFromRGB(0x666666);
  47. self.couponDateLabel.textColor = UIColorFromRGB(0x666666);
  48. NSDateComponents* dateComonents = [FLStringHelper convertToComponentsFormateFromString:item.expiryDate baseTime:serveTime];
  49. if (dateComonents && dateComonents.day <= 2) {
  50. self.expireImageView.hidden = NO;
  51. } else {
  52. self.expireImageView.hidden = YES;
  53. }
  54. } else {
  55. self.topBanner.backgroundColor = UIColorFromRGB(0xcccccc);
  56. self.couponNameLabel.textColor = UIColorFromRGB(0x999999);
  57. self.couponDetailLabel.textColor = UIColorFromRGB(0x999999);
  58. self.couponRuleLabel.textColor = UIColorFromRGB(0xcccccc);
  59. self.couponDateLabel.textColor = UIColorFromRGB(0xcccccc);
  60. self.expireImageView.hidden = YES;
  61. }
  62. }
  63. - (void)addAllSubViews {
  64. [self.contentView addSubview:self.bgView];
  65. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.equalTo(self.contentView).offset(10);
  67. make.right.bottom.equalTo(self.contentView).with.offset(-10);
  68. make.top.equalTo(self.contentView);
  69. }];
  70. [self.bgView addSubview:self.topBanner];
  71. [self.topBanner mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.top.right.equalTo(self.bgView);
  73. make.height.mas_equalTo(6);
  74. }];
  75. [self.bgView addSubview:self.leftDotView];
  76. [self.leftDotView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.equalTo(self.bgView).offset(-5);
  78. make.top.equalTo(self.bgView).offset(75);
  79. make.size.mas_equalTo(CGSizeMake(10, 10));
  80. }];
  81. [self.bgView addSubview:self.rightDotView];
  82. [self.rightDotView mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.centerY.equalTo(self.leftDotView);
  84. make.right.equalTo(self.bgView).offset(5);
  85. make.size.mas_equalTo(CGSizeMake(10, 10));
  86. }];
  87. [self.bgView addSubview:self.separateLine];
  88. [self.separateLine mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.equalTo(self.leftDotView.mas_right).offset(12);
  90. make.right.equalTo(self.rightDotView.mas_left).offset(-12);
  91. make.centerY.equalTo(self.leftDotView);
  92. make.height.mas_equalTo(1);
  93. }];
  94. [self.bgView addSubview:self.couponNameLabel];
  95. [self.couponNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(self.bgView).offset(16);
  97. make.top.equalTo(self.bgView).offset(16);
  98. }];
  99. [self.bgView addSubview:self.couponDetailLabel];
  100. [self.couponDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.equalTo(self.couponNameLabel);
  102. make.top.equalTo(self.couponNameLabel.mas_bottom).offset(2);
  103. }];
  104. [self.bgView addSubview:self.couponRuleLabel];
  105. [self.couponRuleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.equalTo(self.bgView).offset(14);
  107. make.right.equalTo(self.bgView).offset(-14);
  108. make.top.equalTo(self.separateLine.mas_bottom).offset(6);
  109. make.height.mas_equalTo(40);
  110. }];
  111. [self.bgView addSubview:self.couponDateLabel];
  112. [self.couponDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.equalTo(self.couponRuleLabel);
  114. make.bottom.equalTo(self.bgView).offset(-20);
  115. }];
  116. [self.bgView addSubview:self.invalidBgView];
  117. [self.invalidBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.right.equalTo(self.bgView).offset(-15);
  119. make.top.equalTo(self.bgView).offset(18);
  120. make.size.mas_equalTo(CGSizeMake(72, 48));
  121. }];
  122. [self.bgView addSubview:self.bottomSpotLine];
  123. [self.bottomSpotLine mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.equalTo(self.bgView);
  125. make.right.equalTo(self.bgView).offset(-6);
  126. make.bottom.equalTo(self.bgView);
  127. make.height.mas_equalTo(3.5);
  128. }];
  129. [self.bgView addSubview:self.expireImageView];
  130. [self.expireImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.top.right.equalTo(self.bgView);
  132. }];
  133. }
  134. #pragma mark -
  135. - (UIView*)bgView {
  136. if (!_bgView) {
  137. _bgView = [[UIView alloc] init];
  138. _bgView.backgroundColor = [UIColor whiteColor];
  139. }
  140. return _bgView;
  141. }
  142. - (UIView*)topBanner {
  143. if (!_topBanner) {
  144. _topBanner = [[UIView alloc] init];
  145. }
  146. return _topBanner;
  147. }
  148. - (UIView*)leftDotView {
  149. if (!_leftDotView) {
  150. _leftDotView = [[UIView alloc] init];
  151. _leftDotView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  152. _leftDotView.layer.cornerRadius = 5;
  153. }
  154. return _leftDotView;
  155. }
  156. - (UIView*)rightDotView {
  157. if (!_rightDotView) {
  158. _rightDotView = [[UIView alloc] init];
  159. _rightDotView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  160. _rightDotView.layer.cornerRadius = 5;
  161. }
  162. return _rightDotView;
  163. }
  164. - (UIImageView *)separateLine{
  165. if (!_separateLine) {
  166. UIImage *sizedImg = [[UIImage imageNamed:@"point_line_single"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeTile];
  167. _separateLine = [[UIImageView alloc]initWithImage:sizedImg];
  168. }
  169. return _separateLine;
  170. }
  171. - (UIImageView *)bottomSpotLine{
  172. if (!_bottomSpotLine) {
  173. UIImage *sizedImg = [[UIImage imageNamed:@"bottom_spot_icon"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeTile];
  174. _bottomSpotLine = [[UIImageView alloc]initWithImage:sizedImg];
  175. }
  176. return _bottomSpotLine;
  177. }
  178. - (UILabel *)couponNameLabel {
  179. if (!_couponNameLabel) {
  180. _couponNameLabel = [[UILabel alloc] init];
  181. _couponNameLabel.font = [UIFont boldSystemFontOfSize:22];
  182. }
  183. return _couponNameLabel;
  184. }
  185. - (UILabel *)couponDetailLabel {
  186. if (!_couponDetailLabel) {
  187. _couponDetailLabel = [[UILabel alloc] init];
  188. _couponDetailLabel.font = [UIFont systemFontOfSize:15];
  189. }
  190. return _couponDetailLabel;
  191. }
  192. - (UILabel *)couponRuleLabel {
  193. if (!_couponRuleLabel) {
  194. _couponRuleLabel = [[UILabel alloc] init];
  195. _couponRuleLabel.font = [UIFont systemFontOfSize:14];
  196. _couponRuleLabel.numberOfLines = 0;
  197. }
  198. return _couponRuleLabel;
  199. }
  200. - (UILabel *)couponDateLabel {
  201. if (!_couponDateLabel) {
  202. _couponDateLabel = [[UILabel alloc] init];
  203. _couponDateLabel.font = [UIFont systemFontOfSize:14];
  204. _couponDateLabel.textAlignment = NSTextAlignmentCenter;
  205. }
  206. return _couponDateLabel;
  207. }
  208. - (UIImageView *)invalidBgView {
  209. if (!_invalidBgView) {
  210. _invalidBgView = [[UIImageView alloc] init];
  211. _invalidBgView.image = [UIImage imageNamed:@"CouponInvalidIcon"];
  212. }
  213. return _invalidBgView;
  214. }
  215. -(UIImageView *)expireImageView {
  216. if (!_expireImageView) {
  217. UIImage *expireImage = [UIImage imageNamed:@"will_expire"];
  218. _expireImageView = [[UIImageView alloc] initWithImage:expireImage];
  219. _expireImageView.hidden = YES;
  220. }
  221. return _expireImageView;
  222. }
  223. #pragma mark -
  224. + (CGFloat)height {
  225. return (80 + 6 + 42 + 6 + 35 + 6);
  226. }
  227. @end