ASCouponListCell.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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)setVipCouponStyle {
  50. self.codeLb.hidden = true;
  51. self.codeTitleLb.text = @"COUPONS";
  52. self.cpLb.text = @"GET";
  53. self.usedLb.text = @"GOT";
  54. }
  55. - (void)setGiftCardStyle {
  56. self.codeLb.hidden = true;
  57. self.codeTitleLb.text = @"GIFTCARD";
  58. self.cpLb.text = @"USE";
  59. }
  60. - (void)setStatus:(BOOL)isUsed {
  61. self.usedLb.hidden = !isUsed;
  62. self.cpBt.hidden = isUsed;
  63. self.titleLb.textColor = isUsed ? _DBDBDB : Col_000;
  64. self.ruleLb.textColor = isUsed ? _DBDBDB : _043632;
  65. self.dateLb.textColor = isUsed ? _DBDBDB : _128273;
  66. self.codeTitleLb.textColor = isUsed ? Col_FFF : _043632;
  67. self.codeLb.textColor = isUsed ? Col_FFF : _043632;
  68. self.bg1.image = [UIImage imageNamed:isUsed ? @"uc_coupon_colorBg1_sel" : @"uc_coupon_colorBg1"];
  69. self.bg2.image = [UIImage imageNamed:isUsed ? @"uc_coupon_colorBg2_sel" : @"uc_coupon_colorBg2"];
  70. self.ln1.image = [UIImage imageNamed:isUsed ? @"uc_coupon_line1_sel" : @"uc_coupon_line1"];
  71. self.ln2.image = [UIImage imageNamed:isUsed ? @"uc_coupon_line2_sel" : @"uc_coupon_line2"];
  72. self.sep.image = [UIImage imageNamed:isUsed ? @"uc_coupon_sep_sel" : @"uc_coupon_sep"];
  73. }
  74. - (void)loadSubVs {
  75. self.backgroundColor = UIColor.clearColor;
  76. self.contentView.backgroundColor = UIColor.clearColor;
  77. self.selectionStyle = UITableViewCellSelectionStyleNone;
  78. [self.contentView addSubview:self.bgV];
  79. [self.bgV addSubview:self.bg1];
  80. [self.bgV addSubview:self.bg2];
  81. [self.bgV addSubview:self.ln1];
  82. [self.bgV addSubview:self.ln2];
  83. [self.bgV addSubview:self.sep];
  84. //229/106
  85. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.height.equalTo(@100);
  87. make.leading.equalTo(self.contentView).offset(20);
  88. make.trailing.equalTo(self.contentView).offset(-20);
  89. make.top.equalTo(self.contentView).offset(15);
  90. make.bottom.equalTo(self.contentView).offset(-5);
  91. }];
  92. [self.bg1 mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.edges.equalTo(self.bgV);
  94. }];
  95. [self.bg2 mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.top.bottom.trailing.equalTo(self.bgV);
  97. make.width.equalTo(self.bgV).multipliedBy(106.0/(229+106));
  98. }];
  99. [self.sep mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.width.equalTo(@3);
  101. make.top.bottom.equalTo(self.bgV);
  102. make.centerX.equalTo(self.bg2.mas_leading);
  103. }];
  104. [self.ln1 mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.edges.equalTo(self.bgV);
  106. }];
  107. [self.ln2 mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.leading.equalTo(self.bgV).offset(5);
  109. make.trailing.equalTo(self.bgV).offset(-5);
  110. make.top.equalTo(self.bgV).offset(5);
  111. make.bottom.equalTo(self.bgV).offset(-5);
  112. }];
  113. [self.bgV addSubview:self.titleLb];
  114. [self.bgV addSubview:self.ruleLb];
  115. [self.bgV addSubview:self.dateLb];
  116. UIStackView *st = [UIStackView baseStackV:true];
  117. st.spacing = 0;
  118. st.distribution = UIStackViewDistributionFill;
  119. [self.bgV addSubview:st];
  120. [st addArrangedSubview:self.cpLb];
  121. [st addArrangedSubview:self.codeTitleLb];
  122. [st addArrangedSubview:self.codeLb];
  123. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.top.equalTo(self.bgV).offset(16);
  125. make.leading.equalTo(self.bgV).offset(30);
  126. make.trailing.equalTo(self.sep.mas_leading).offset(-8);
  127. make.height.equalTo(@34);
  128. }];
  129. [self.ruleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.top.equalTo(self.titleLb.mas_bottom);
  131. make.leading.trailing.equalTo(self.titleLb);
  132. make.height.equalTo(@14);
  133. }];
  134. [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.top.equalTo(self.ruleLb.mas_bottom).offset(6);
  136. make.leading.trailing.equalTo(self.titleLb);
  137. make.height.equalTo(@14);
  138. }];
  139. [st mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.centerY.equalTo(self.bg2);
  141. make.centerX.equalTo(self.bg2).offset(-8);
  142. make.width.equalTo(@80);
  143. }];
  144. [self.cpLb mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.height.equalTo(@34);
  146. }];
  147. [self.codeTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.height.equalTo(@17);
  149. }];
  150. [self.codeLb mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.height.equalTo(@17);
  152. }];
  153. [self.bgV addSubview:self.cpBt];
  154. [self.cpBt mas_makeConstraints:^(MASConstraintMaker *make) {
  155. make.edges.equalTo(self.bg2);
  156. }];
  157. st.transform = CGAffineTransformRotate(st.transform, -M_PI/2.0);
  158. [self.bgV addSubview:self.usedLb];
  159. [self.usedLb mas_makeConstraints:^(MASConstraintMaker *make) {
  160. make.center.equalTo(self.bgV);
  161. }];
  162. self.usedLb.transform = CGAffineTransformRotate(self.usedLb.transform, -M_PI/6.0);
  163. }
  164. - (UIView *)bgV {
  165. if (!_bgV) {
  166. UIView *v = [UIView baseV];
  167. v.backgroundColor = UIColor.clearColor;
  168. v.clipsToBounds = true;
  169. _bgV = v;
  170. }
  171. return _bgV;
  172. }
  173. - (UIImageView *)bg1 {
  174. if (!_bg1) {
  175. UIImageView *v = [UIImageView baseImgV];
  176. v.contentMode = UIViewContentModeScaleToFill;
  177. v.clipsToBounds = true;
  178. v.image = [UIImage imageNamed:@"uc_coupon_colorBg1"];
  179. _bg1 = v;
  180. }
  181. return _bg1;
  182. }
  183. - (UIImageView *)bg2 {
  184. if (!_bg2) {
  185. UIImageView *v = [UIImageView baseImgV];
  186. v.contentMode = UIViewContentModeScaleToFill;
  187. v.userInteractionEnabled = true;
  188. v.clipsToBounds = true;
  189. v.image = [UIImage imageNamed:@"uc_coupon_colorBg2"];
  190. _bg2 = v;
  191. }
  192. return _bg2;
  193. }
  194. - (UIImageView *)ln1 {
  195. if (!_ln1) {
  196. UIImageView *v = [UIImageView baseImgV];
  197. v.contentMode = UIViewContentModeScaleToFill;
  198. v.clipsToBounds = true;
  199. v.image = [UIImage imageNamed:@"uc_coupon_line1"];
  200. _ln1 = v;
  201. }
  202. return _ln1;
  203. }
  204. - (UIImageView *)ln2 {
  205. if (!_ln2) {
  206. UIImageView *v = [UIImageView baseImgV];
  207. v.contentMode = UIViewContentModeScaleToFill;
  208. v.clipsToBounds = true;
  209. v.image = [UIImage imageNamed:@"uc_coupon_line2"];
  210. _ln2 = v;
  211. }
  212. return _ln2;
  213. }
  214. - (UIImageView *)sep {
  215. if (!_sep) {
  216. UIImageView *v = [UIImageView baseImgV];
  217. v.contentMode = UIViewContentModeScaleAspectFill;
  218. v.clipsToBounds = true;
  219. v.image = [UIImage imageNamed:@"uc_coupon_sep"];
  220. _sep = v;
  221. }
  222. return _sep;
  223. }
  224. - (UILabel *)titleLb {
  225. if (!_titleLb) {
  226. UILabel *lb = [UILabel baseLb];
  227. lb.font = [UIFont fontWithName:Rob_BlackItalic size:28];
  228. lb.textColor = Col_000;
  229. _titleLb = lb;
  230. }
  231. return _titleLb;
  232. }
  233. - (UILabel *)ruleLb {
  234. if (!_ruleLb) {
  235. UILabel *lb = [UILabel baseLb];
  236. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  237. lb.textColor = _043632;
  238. _ruleLb = lb;
  239. }
  240. return _ruleLb;
  241. }
  242. - (UILabel *)dateLb {
  243. if (!_dateLb) {
  244. UILabel *lb = [UILabel baseLb];
  245. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  246. lb.textColor = _128273;
  247. _dateLb = lb;
  248. }
  249. return _dateLb;
  250. }
  251. - (UILabel *)cpLb {
  252. if (!_cpLb) {
  253. UILabel *lb = [UILabel baseLb];
  254. lb.font = [UIFont fontWithName:Rob_Black size:28];
  255. lb.textColor = Col_FFF;
  256. lb.text = @"COPY";
  257. lb.textAlignment = NSTextAlignmentCenter;
  258. _cpLb = lb;
  259. }
  260. return _cpLb;
  261. }
  262. - (UILabel *)codeTitleLb {
  263. if (!_codeTitleLb) {
  264. UILabel *lb = [UILabel baseLb];
  265. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  266. lb.textAlignment = NSTextAlignmentCenter;
  267. lb.textColor = _043632;
  268. lb.text = @"CODE";
  269. _codeTitleLb = lb;
  270. }
  271. return _codeTitleLb;
  272. }
  273. - (UILabel *)codeLb {
  274. if (!_codeLb) {
  275. UILabel *lb = [UILabel baseLb];
  276. lb.textAlignment = NSTextAlignmentCenter;
  277. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  278. lb.textColor = _043632;
  279. _codeLb = lb;
  280. }
  281. return _codeLb;
  282. }
  283. - (UILabel *)usedLb {
  284. if (!_usedLb) {
  285. UILabel *lb = [UILabel baseLb];
  286. lb.textAlignment = NSTextAlignmentCenter;
  287. lb.font = [UIFont fontWithName:Rob_Bold size:48];
  288. lb.textColor = Col_666;
  289. lb.text = @"USED";
  290. lb.hidden = true;
  291. _usedLb = lb;
  292. }
  293. return _usedLb;
  294. }
  295. - (UIButton *)cpBt {
  296. if (!_cpBt) {
  297. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  298. [bt addTarget: self action:@selector(copyAction) forControlEvents:UIControlEventTouchUpInside];
  299. _cpBt = bt;
  300. }
  301. return _cpBt;
  302. }
  303. - (void)copyAction {
  304. if (!self.codeLb.text.isEmpty) {
  305. UIPasteboard.generalPasteboard.string = self.codeLb.text;
  306. }
  307. if (self.copyCallBack){
  308. self.copyCallBack();
  309. }
  310. }
  311. @end