《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRGoodCollectionCell.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. //
  2. // DRGoodCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRGoodCollectionCell.h"
  9. #import "DRGoodTagsView.h"
  10. @interface DRGoodCollectionCell ()
  11. @property (nonatomic, strong) UIImageView *imgView; //大图
  12. @property (nonatomic, strong) YYLabel *titleLabel; //标题
  13. @property (nonatomic, strong) YYLabel *priceLabel; //原价
  14. @property (nonatomic, strong) UILabel *saleCount; // 月销量
  15. @property (nonatomic, strong) YYLabel *disPriceL; // 优惠后价格
  16. @property (nonatomic, strong) UIImageView *ticketNumber; //
  17. @property (nonatomic, strong) UILabel *totalCount; // 总件数
  18. @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券
  19. @property (nonatomic, strong) UILabel *ticketType;
  20. @property (nonatomic, strong) UILabel *volum;
  21. @property (nonatomic, strong) DRGoodTagsView *tagsView;
  22. @property (nonatomic, strong) YYLabel *shopInfo;
  23. @end
  24. @implementation DRGoodCollectionCell
  25. - (instancetype)initWithFrame:(CGRect)frame {
  26. self = [super initWithFrame:frame];
  27. if (self) {
  28. self.layer.cornerRadius = 6;
  29. self.layer.masksToBounds = YES;
  30. self.contentView.backgroundColor = [UIColor whiteColor];
  31. [self initSubViews];
  32. }
  33. return self;
  34. }
  35. - (void)initSubViews {
  36. [self.contentView addSubview:self.imgView];
  37. [self.contentView addSubview:self.titleLabel];
  38. [self.contentView addSubview:self.disPriceL];
  39. [self.contentView addSubview:self.ticketNumber];
  40. [self.ticketNumber addSubview:self.ticketType];
  41. [self.ticketNumber addSubview:self.zheKou];
  42. [self.contentView addSubview:self.saleCount];
  43. [self.contentView addSubview:self.shopInfo];
  44. [self.contentView addSubview:self.volum];
  45. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.right.top.mas_equalTo(0);
  47. make.height.mas_equalTo((SCREEN_WIDTH-5)/2.f);
  48. }];
  49. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.mas_equalTo(10);
  51. make.right.mas_equalTo(-10);
  52. make.top.mas_equalTo(self.imgView.mas_bottom).mas_offset(4);
  53. }];
  54. [self.shopInfo mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(self.titleLabel.mas_left);
  56. make.right.mas_equalTo(-10);
  57. make.top.mas_equalTo(self.imgView.mas_bottom).mas_offset(45);
  58. }];
  59. [self.disPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(self.titleLabel.mas_left).mas_offset(-2);
  61. make.top.mas_equalTo(self.shopInfo.mas_bottom).mas_offset(5);
  62. }];
  63. [self.volum mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(10);
  65. make.centerY.mas_equalTo(self.disPriceL.mas_centerY);
  66. }];
  67. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(self.titleLabel.mas_left);
  69. make.width.mas_equalTo(64);
  70. make.height.mas_equalTo(14);
  71. make.bottom.mas_equalTo(-7);
  72. }];
  73. [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.top.bottom.mas_equalTo(0);
  75. make.width.mas_equalTo(20);
  76. }];
  77. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(self.ticketType.mas_right);
  79. make.top.mas_equalTo(0);
  80. make.height.mas_equalTo(14);
  81. make.width.mas_equalTo(44);
  82. }];
  83. // [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  84. // make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(5);
  85. // make.bottom.mas_equalTo(self.disPriceL.mas_bottom).mas_offset(-2);
  86. // }];
  87. //
  88. // [self.tagsView mas_makeConstraints:^(MASConstraintMaker *make) {
  89. // make.left.mas_equalTo(self.ticketNumber.mas_right).mas_offset(5);
  90. // make.centerY.mas_equalTo(self.ticketNumber.mas_centerY);
  91. // make.width.mas_equalTo(80);
  92. // make.height.mas_equalTo(12);
  93. // }];
  94. //
  95. }
  96. - (void)setModel:(DRChildGoodModel *)model {
  97. _model = model;
  98. //标题
  99. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
  100. attri.yy_font = [UIFont boldSystemFontOfSize:14];
  101. attri.yy_color = [UIColor blackColor];
  102. attri.yy_lineSpacing = 6;
  103. self.titleLabel.attributedText = attri;
  104. [self.imgView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  105. NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  106. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price];
  107. attrStr.yy_font = [UIFont systemFontOfSize:11];
  108. attrStr.yy_color = [UIColor YHColorWithHex:0x999999];
  109. YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]];
  110. [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)];
  111. self.priceLabel.attributedText = attrStr;
  112. self.volum.text = [NSString stringWithFormat:@"月销 %@",model.volume];
  113. //店铺信息
  114. if (model.shop_title.length > 0) {
  115. UIImage *img;
  116. if ([model.shop_type isEqualToString:@"1"]) {
  117. img= [UIImage imageNamed:@"tm_shop"];
  118. }else {
  119. img= [UIImage imageNamed:@"taobao_shop"];
  120. }
  121. YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
  122. imgeView.frame = CGRectMake(0, 0, 15, 15);
  123. NSMutableAttributedString *shopAtti = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.shop_title]];
  124. NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
  125. [shopAtti insertAttributedString:mua atIndex:0];
  126. shopAtti.yy_font = [UIFont systemFontOfSize:12];
  127. shopAtti.yy_color = [UIColor YHColorWithHex:0x9B9B9B];
  128. self.shopInfo.attributedText = shopAtti;
  129. self.shopInfo.hidden = NO;
  130. }else {
  131. self.shopInfo.hidden = YES;
  132. }
  133. //折后价
  134. NSString *disStr;
  135. if ([model.is_coupon boolValue]) {
  136. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  137. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  138. self.ticketType.text = @"券";
  139. }else {
  140. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  141. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  142. self.ticketType.text = @"折";
  143. }
  144. CGFloat width = [model.is_coupon boolValue] ? 64 : 0;
  145. // [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  146. // make.width.mas_equalTo(width);
  147. // }];
  148. //券后价格
  149. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  150. [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(0, disStr.length)];
  151. disAttr.yy_color = [UIColor homeRedColor];
  152. self.disPriceL.attributedText = disAttr;
  153. //券相关
  154. self.ticketNumber.hidden = ![model.is_coupon boolValue];
  155. }
  156. - (UIImageView *)imgView {
  157. if (!_imgView) {
  158. _imgView = [[UIImageView alloc] init];
  159. _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0];
  160. }
  161. return _imgView;
  162. }
  163. - (YYLabel *)titleLabel {
  164. if (!_titleLabel) {
  165. _titleLabel = [[YYLabel alloc] init];
  166. _titleLabel.displaysAsynchronously = YES;
  167. _titleLabel.font = [UIFont boldSystemFontOfSize:14];
  168. _titleLabel.textColor = [UIColor blackColor];
  169. _titleLabel.numberOfLines = 2;
  170. _titleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH/2-Fitsize(20);
  171. }
  172. return _titleLabel;
  173. }
  174. - (YYLabel *)priceLabel {
  175. if (!_priceLabel) {
  176. _priceLabel = [[YYLabel alloc] init];
  177. _priceLabel.displaysAsynchronously = YES;
  178. _priceLabel.font = [UIFont systemFontOfSize:11];
  179. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  180. }
  181. return _priceLabel;
  182. }
  183. - (UILabel *)saleCount {
  184. if (!_saleCount) {
  185. _saleCount = [[UILabel alloc] init];
  186. _saleCount.font = [UIFont systemFontOfSize:10];
  187. _saleCount.textColor = [UIColor YHColorWithHex:0x999999];
  188. _saleCount.textAlignment = NSTextAlignmentRight;
  189. _saleCount.hidden = YES;
  190. }
  191. return _saleCount;
  192. }
  193. - (YYLabel *)disPriceL {
  194. if (!_disPriceL) {
  195. _disPriceL = [[YYLabel alloc] init];
  196. _disPriceL.displaysAsynchronously = YES;
  197. _disPriceL.font = [UIFont systemFontOfSize:16];
  198. _disPriceL.textColor = [UIColor homeRedColor];
  199. }
  200. return _disPriceL;
  201. }
  202. - (UIImageView *)ticketNumber {
  203. if (!_ticketNumber) {
  204. _ticketNumber = [[UIImageView alloc] init];
  205. _ticketNumber.image = [UIImage imageNamed:@"quan_bg"];
  206. }
  207. return _ticketNumber;
  208. }
  209. - (UILabel *)totalCount {
  210. if (!_totalCount) {
  211. _totalCount = [[UILabel alloc] init];
  212. _totalCount.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  213. _totalCount.layer.cornerRadius = 3;
  214. _totalCount.font = [UIFont systemFontOfSize:10];
  215. _totalCount.textAlignment = NSTextAlignmentCenter;
  216. _totalCount.textColor = [UIColor YHColorWithHex:0xffffff];
  217. }
  218. return _totalCount;
  219. }
  220. - (UILabel *)zheKou {
  221. if (!_zheKou) {
  222. _zheKou = [[UILabel alloc] init];
  223. _zheKou.textColor = [UIColor homeRedColor];
  224. _zheKou.textAlignment = NSTextAlignmentCenter;
  225. _zheKou.font = [UIFont systemFontOfSize:10];
  226. }
  227. return _zheKou;
  228. }
  229. - (UILabel *)ticketType {
  230. if (!_ticketType) {
  231. _ticketType = [[UILabel alloc] init];
  232. _ticketType.font = [UIFont systemFontOfSize:10];
  233. _ticketType.textAlignment = NSTextAlignmentCenter;
  234. _ticketType.textColor = [UIColor homeRedColor];
  235. }
  236. return _ticketType;
  237. }
  238. - (YYLabel *)shopInfo {
  239. if (!_shopInfo) {
  240. _shopInfo = [[YYLabel alloc] init];
  241. _shopInfo.displaysAsynchronously = YES;
  242. _shopInfo.font = [UIFont systemFontOfSize:12];
  243. _shopInfo.textColor = [UIColor YHColorWithHex:0x9B9B9B];
  244. }
  245. return _shopInfo;
  246. }
  247. - (UILabel *)volum {
  248. if (!_volum) {
  249. _volum = [[UILabel alloc] init];
  250. _volum.textColor = [UIColor YHColorWithHex:0xBBB9BB];
  251. _volum.font = [UIFont systemFontOfSize:10];
  252. }
  253. return _volum;
  254. }
  255. //- (DRGoodTagsView *)tagsView {
  256. // if (!_tagsView) {
  257. // _tagsView = [[DRGoodTagsView alloc] init];
  258. // }
  259. // return _tagsView;
  260. //}
  261. @end