ASCouponListCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. //
  2. // ASCouponListCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/25.
  6. //
  7. #import "ASCouponListCell.h"
  8. @interface ASCouponListCell ()
  9. @property (nonatomic, strong) UIView *bgV;
  10. @property (nonatomic, strong) UIImageView *bg1;
  11. @property (nonatomic, strong) UIImageView *bg2;
  12. @property (nonatomic, strong) UIImageView *ln1;
  13. @property (nonatomic, strong) UIImageView *ln2;
  14. @property (nonatomic, strong) UIImageView *sep;
  15. @property (nonatomic, strong) UILabel *titleLb;
  16. @property (nonatomic, strong) UILabel *ruleLb;
  17. @property (nonatomic, strong) UILabel *dateLb;
  18. @property (nonatomic, strong) UILabel *cpLb;
  19. @property (nonatomic, strong) UILabel *codeTitleLb;
  20. @property (nonatomic, strong) UILabel *codeLb;
  21. @property (nonatomic, strong) UIButton *cpBt;
  22. @property (nonatomic, strong) UILabel *usedLb;
  23. @end
  24. @implementation ASCouponListCell
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. // Initialization code
  28. }
  29. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  30. [super setSelected:selected animated:animated];
  31. // Configure the view for the selected state
  32. }
  33. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  34. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  35. if (self)
  36. {
  37. [self loadSubVs];
  38. [self setDemoData];
  39. }
  40. return self;
  41. }
  42. - (void)setDemoData {
  43. self.titleLb.text = @"$10 off";
  44. self.ruleLb.text = @"For Order ≥ $99";
  45. self.dateLb.text = @"DTAE:2022/09/01-2022/09/30";
  46. self.codeLb.text = @"3VIP55";
  47. [self setStatus:arc4random()%2==1];
  48. }
  49. - (void)setStatus:(BOOL)isUsed {
  50. self.usedLb.hidden = !isUsed;
  51. self.cpBt.hidden = isUsed;
  52. self.titleLb.textColor = isUsed ? _DBDBDB : Col_000;
  53. self.ruleLb.textColor = isUsed ? _DBDBDB : _043632;
  54. self.dateLb.textColor = isUsed ? _DBDBDB : _128273;
  55. self.codeTitleLb.textColor = isUsed ? Col_FFF : _043632;
  56. self.codeLb.textColor = isUsed ? Col_FFF : _043632;
  57. self.bg1.image = [UIImage imageNamed:isUsed ? @"uc_coupon_colorBg1_sel" : @"uc_coupon_colorBg1"];
  58. self.bg2.image = [UIImage imageNamed:isUsed ? @"uc_coupon_colorBg2_sel" : @"uc_coupon_colorBg2"];
  59. self.ln1.image = [UIImage imageNamed:isUsed ? @"uc_coupon_line1_sel" : @"uc_coupon_line1"];
  60. self.ln2.image = [UIImage imageNamed:isUsed ? @"uc_coupon_line2_sel" : @"uc_coupon_line2"];
  61. self.sep.image = [UIImage imageNamed:isUsed ? @"uc_coupon_sep_sel" : @"uc_coupon_sep"];
  62. }
  63. - (void)loadSubVs {
  64. self.backgroundColor = UIColor.clearColor;
  65. self.contentView.backgroundColor = UIColor.clearColor;
  66. self.selectionStyle = UITableViewCellSelectionStyleNone;
  67. [self.contentView addSubview:self.bgV];
  68. [self.bgV addSubview:self.bg1];
  69. [self.bgV addSubview:self.bg2];
  70. [self.bgV addSubview:self.ln1];
  71. [self.bgV addSubview:self.ln2];
  72. [self.bgV addSubview:self.sep];
  73. //229/106
  74. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.height.equalTo(@100);
  76. make.leading.equalTo(self.contentView).offset(20);
  77. make.trailing.equalTo(self.contentView).offset(-20);
  78. make.top.equalTo(self.contentView).offset(15);
  79. make.bottom.equalTo(self.contentView).offset(-5);
  80. }];
  81. [self.bg1 mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.edges.equalTo(self.bgV);
  83. }];
  84. [self.bg2 mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.top.bottom.trailing.equalTo(self.bgV);
  86. make.width.equalTo(self.bgV).multipliedBy(106.0/(229+106));
  87. }];
  88. [self.sep mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.width.equalTo(@3);
  90. make.top.bottom.equalTo(self.bgV);
  91. make.centerX.equalTo(self.bg2.mas_leading);
  92. }];
  93. [self.ln1 mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.edges.equalTo(self.bgV);
  95. }];
  96. [self.ln2 mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.leading.equalTo(self.bgV).offset(5);
  98. make.trailing.equalTo(self.bgV).offset(-5);
  99. make.top.equalTo(self.bgV).offset(5);
  100. make.bottom.equalTo(self.bgV).offset(-5);
  101. }];
  102. [self.bgV addSubview:self.titleLb];
  103. [self.bgV addSubview:self.ruleLb];
  104. [self.bgV addSubview:self.dateLb];
  105. UIStackView *st = [UIStackView baseStackV:true];
  106. st.spacing = 0;
  107. st.distribution = UIStackViewDistributionFill;
  108. [self.bgV addSubview:st];
  109. [st addArrangedSubview:self.cpLb];
  110. [st addArrangedSubview:self.codeTitleLb];
  111. [st addArrangedSubview:self.codeLb];
  112. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.equalTo(self.bgV).offset(16);
  114. make.leading.equalTo(self.bgV).offset(30);
  115. make.trailing.equalTo(self.sep.mas_leading).offset(-8);
  116. make.height.equalTo(@34);
  117. }];
  118. [self.ruleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.top.equalTo(self.titleLb.mas_bottom);
  120. make.leading.trailing.equalTo(self.titleLb);
  121. make.height.equalTo(@14);
  122. }];
  123. [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.top.equalTo(self.ruleLb.mas_bottom).offset(6);
  125. make.leading.trailing.equalTo(self.titleLb);
  126. make.height.equalTo(@14);
  127. }];
  128. [st mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.centerY.equalTo(self.bg2);
  130. make.centerX.equalTo(self.bg2).offset(-8);
  131. make.width.equalTo(@80);
  132. }];
  133. [self.cpLb mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.height.equalTo(@34);
  135. }];
  136. [self.codeTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.height.equalTo(@17);
  138. }];
  139. [self.codeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.height.equalTo(@17);
  141. }];
  142. [self.bg2 addSubview:self.cpBt];
  143. [self.cpBt mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.edges.equalTo(self.bg2);
  145. }];
  146. st.transform = CGAffineTransformRotate(st.transform, -M_PI/2.0);
  147. [self.bgV addSubview:self.usedLb];
  148. [self.usedLb mas_makeConstraints:^(MASConstraintMaker *make) {
  149. make.center.equalTo(self.bgV);
  150. }];
  151. self.usedLb.transform = CGAffineTransformRotate(self.usedLb.transform, -M_PI/6.0);
  152. }
  153. - (UIView *)bgV {
  154. if (!_bgV) {
  155. UIView *v = [UIView baseV];
  156. v.backgroundColor = UIColor.clearColor;
  157. v.clipsToBounds = true;
  158. _bgV = v;
  159. }
  160. return _bgV;
  161. }
  162. - (UIImageView *)bg1 {
  163. if (!_bg1) {
  164. UIImageView *v = [UIImageView baseImgV];
  165. v.contentMode = UIViewContentModeScaleToFill;
  166. v.clipsToBounds = true;
  167. v.image = [UIImage imageNamed:@"uc_coupon_colorBg1"];
  168. _bg1 = v;
  169. }
  170. return _bg1;
  171. }
  172. - (UIImageView *)bg2 {
  173. if (!_bg2) {
  174. UIImageView *v = [UIImageView baseImgV];
  175. v.contentMode = UIViewContentModeScaleToFill;
  176. v.userInteractionEnabled = true;
  177. v.clipsToBounds = true;
  178. v.image = [UIImage imageNamed:@"uc_coupon_colorBg2"];
  179. _bg2 = v;
  180. }
  181. return _bg2;
  182. }
  183. - (UIImageView *)ln1 {
  184. if (!_ln1) {
  185. UIImageView *v = [UIImageView baseImgV];
  186. v.contentMode = UIViewContentModeScaleToFill;
  187. v.clipsToBounds = true;
  188. v.image = [UIImage imageNamed:@"uc_coupon_line1"];
  189. _ln1 = v;
  190. }
  191. return _ln1;
  192. }
  193. - (UIImageView *)ln2 {
  194. if (!_ln2) {
  195. UIImageView *v = [UIImageView baseImgV];
  196. v.contentMode = UIViewContentModeScaleToFill;
  197. v.clipsToBounds = true;
  198. v.image = [UIImage imageNamed:@"uc_coupon_line2"];
  199. _ln2 = v;
  200. }
  201. return _ln2;
  202. }
  203. - (UIImageView *)sep {
  204. if (!_sep) {
  205. UIImageView *v = [UIImageView baseImgV];
  206. v.contentMode = UIViewContentModeScaleAspectFill;
  207. v.clipsToBounds = true;
  208. v.image = [UIImage imageNamed:@"uc_coupon_sep"];
  209. _sep = v;
  210. }
  211. return _sep;
  212. }
  213. - (UILabel *)titleLb {
  214. if (!_titleLb) {
  215. UILabel *lb = [UILabel baseLb];
  216. lb.font = [UIFont fontWithName:Rob_BlackItalic size:28];
  217. lb.textColor = Col_000;
  218. _titleLb = lb;
  219. }
  220. return _titleLb;
  221. }
  222. - (UILabel *)ruleLb {
  223. if (!_ruleLb) {
  224. UILabel *lb = [UILabel baseLb];
  225. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  226. lb.textColor = _043632;
  227. _ruleLb = lb;
  228. }
  229. return _ruleLb;
  230. }
  231. - (UILabel *)dateLb {
  232. if (!_dateLb) {
  233. UILabel *lb = [UILabel baseLb];
  234. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  235. lb.textColor = _128273;
  236. _dateLb = lb;
  237. }
  238. return _dateLb;
  239. }
  240. - (UILabel *)cpLb {
  241. if (!_cpLb) {
  242. UILabel *lb = [UILabel baseLb];
  243. lb.font = [UIFont fontWithName:Rob_Black size:28];
  244. lb.textColor = Col_FFF;
  245. lb.text = @"COPY";
  246. lb.textAlignment = NSTextAlignmentCenter;
  247. _cpLb = lb;
  248. }
  249. return _cpLb;
  250. }
  251. - (UILabel *)codeTitleLb {
  252. if (!_codeTitleLb) {
  253. UILabel *lb = [UILabel baseLb];
  254. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  255. lb.textAlignment = NSTextAlignmentCenter;
  256. lb.textColor = _043632;
  257. lb.text = @"CODE";
  258. _codeTitleLb = lb;
  259. }
  260. return _codeTitleLb;
  261. }
  262. - (UILabel *)codeLb {
  263. if (!_codeLb) {
  264. UILabel *lb = [UILabel baseLb];
  265. lb.textAlignment = NSTextAlignmentCenter;
  266. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  267. lb.textColor = _043632;
  268. _codeLb = lb;
  269. }
  270. return _codeLb;
  271. }
  272. - (UILabel *)usedLb {
  273. if (!_usedLb) {
  274. UILabel *lb = [UILabel baseLb];
  275. lb.textAlignment = NSTextAlignmentCenter;
  276. lb.font = [UIFont fontWithName:Rob_Bold size:48];
  277. lb.textColor = Col_666;
  278. lb.text = @"USED";
  279. lb.hidden = true;
  280. _usedLb = lb;
  281. }
  282. return _usedLb;
  283. }
  284. - (UIButton *)cpBt {
  285. if (!_cpBt) {
  286. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  287. [bt addTarget: self action:@selector(copyAction) forControlEvents:UIControlEventTouchUpInside];
  288. _cpBt = bt;
  289. }
  290. return _cpBt;
  291. }
  292. - (void)copyAction {
  293. if (!self.codeLb.text.isEmpty) {
  294. UIPasteboard.generalPasteboard.string = self.codeLb.text;
  295. if (self.copyCallBack){
  296. self.copyCallBack();
  297. }
  298. }
  299. }
  300. @end