ASCouponListCell.m 11 KB

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