ASCouponListCell.m 8.6 KB

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