ASCouponListCell.m 11 KB

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