dkahgld

ZBProductListCell.m 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // ZBProductListCell.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/3/27.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "ZBProductListCell.h"
  9. @implementation ZBProductListCell
  10. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  11. {
  12. self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. if (self) {
  14. self.layer.cornerRadius=6;
  15. self.layer.masksToBounds=YES;
  16. self.backgroundColor=[UIColor whiteColor];
  17. [self addSubview:self.goodImgV];
  18. [self addSubview:self.titleLabel];
  19. [self addSubview:self.shopImg];
  20. [self addSubview:self.shopLabel];
  21. [self addSubview:self.priceLabel];
  22. [self addSubview:self.oldPriceL];
  23. [self addSubview:self.quanImgv];
  24. [self.quanImgv addSubview:self.quanLabel];
  25. [self addSubview:self.salesCountL];
  26. [self addSubview:self.makeLabel];
  27. [self.goodImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.width.height.mas_equalTo(110);
  29. make.top.left.mas_equalTo(10);
  30. }];
  31. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.left.mas_equalTo(self.goodImgV.mas_right).offset(9);
  33. make.right.mas_equalTo(-9);
  34. make.top.mas_equalTo(self.goodImgV.mas_top).offset(5);
  35. make.height.mas_equalTo(22);
  36. }];
  37. [self.shopImg mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.width.height.mas_equalTo(14);
  39. make.left.mas_equalTo(self.goodImgV.mas_right).offset(10);
  40. make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
  41. }];
  42. [self.shopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.mas_equalTo(self.shopImg.mas_right).offset(5);
  44. make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(9);
  45. make.height.mas_equalTo(16);
  46. make.right.mas_equalTo(-10);
  47. }];
  48. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.mas_equalTo(self.shopLabel.mas_bottom).offset(7);
  50. make.left.mas_equalTo(self.goodImgV.mas_right).offset(10);
  51. make.height.mas_equalTo(22);
  52. }];
  53. [self.oldPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(self.shopLabel.mas_bottom).offset(7);
  55. make.left.mas_equalTo(self.priceLabel.mas_right).offset(10);
  56. make.height.mas_equalTo(22);
  57. }];
  58. [self.quanImgv mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.mas_equalTo(self.goodImgV.mas_right).offset(10);
  60. make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(9);
  61. make.height.mas_equalTo(16);
  62. make.width.mas_equalTo(65);
  63. }];
  64. [self.quanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(24);
  66. make.right.top.mas_equalTo(0);
  67. make.height.mas_equalTo(16);
  68. }];
  69. [self.salesCountL mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.right.mas_equalTo(-8);
  71. make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(9);
  72. make.height.mas_equalTo(16);
  73. }];
  74. [self.makeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.top.mas_equalTo(self.oldPriceL.mas_bottom).offset(3);
  76. make.right.mas_equalTo(-8);
  77. make.height.mas_equalTo(26);
  78. make.width.mas_equalTo(80);
  79. }];
  80. }
  81. return self;
  82. }
  83. -(void)setModel:(ZBGoodModel *)model
  84. {
  85. _model= model;
  86. [self.goodImgV sd_setImageWithURL:[NSURL URLWithString:model.img]];
  87. self.titleLabel.text=model.title;
  88. if (model.shop_type.integerValue == 1) {
  89. self.shopImg.image =[UIImage imageNamed:@"tm_icon"];
  90. }else{
  91. self.shopImg.image =[UIImage imageNamed:@"taobao_icon"];
  92. }
  93. self.shopLabel.text=model.shop_title;
  94. self.salesCountL.text=[NSString stringWithFormat:@"月销%@",model.volume];
  95. self.quanLabel.text=[NSString stringWithFormat:@"%@元",model.coupon_price];
  96. //券的价格为0隐藏
  97. if (model.coupon_price.floatValue == 0) {
  98. self.quanImgv.hidden=YES;
  99. }else{
  100. self.quanImgv.hidden=NO;
  101. }
  102. self.priceLabel.text=[NSString stringWithFormat:@"¥%@",model.discount_price];
  103. //原件
  104. NSString *textStr =[NSString stringWithFormat:@"¥%@",model.price];
  105. //中划线
  106. NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
  107. NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
  108. // 赋值
  109. _oldPriceL.attributedText = attribtStr;
  110. NSString *title=[NSString stringWithFormat:@"利润%@",model.commission_rate];
  111. NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:title];
  112. [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,2)]; //设置字体字号和字体类别
  113. [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(2,title.length-2)]; //设置字体字号和字体类别
  114. _makeLabel.attributedText=str;
  115. }
  116. -(UIImageView *)goodImgV
  117. {
  118. if (!_goodImgV) {
  119. _goodImgV=[[UIImageView alloc]init];
  120. _goodImgV.backgroundColor=[UIColor lineColor];
  121. _goodImgV.layer.cornerRadius=4;
  122. _goodImgV.layer.masksToBounds=YES;
  123. }
  124. return _goodImgV;
  125. }
  126. -(UILabel *)titleLabel
  127. {
  128. if (!_titleLabel) {
  129. _titleLabel=[[UILabel alloc]init];
  130. _titleLabel.font=[UIFont systemFontOfSize:15];
  131. _titleLabel.textColor=[UIColor YHColorWithHex:0x333333];
  132. _titleLabel.text=@"---------";
  133. }
  134. return _titleLabel;
  135. }
  136. -(UILabel *)oldPriceL
  137. {
  138. if (!_oldPriceL) {
  139. _oldPriceL=[[UILabel alloc]init];
  140. _oldPriceL.font=[UIFont systemFontOfSize:10];
  141. _oldPriceL.textColor=[UIColor YHColorWithHex:0xBBB9BB];
  142. // _oldPriceL.text=@"99.99";
  143. NSString *textStr =@"¥99.99";
  144. //中划线
  145. NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
  146. NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
  147. // 赋值
  148. _oldPriceL.attributedText = attribtStr;
  149. }
  150. return _oldPriceL;
  151. }
  152. -(UILabel *)priceLabel
  153. {
  154. if (!_priceLabel) {
  155. _priceLabel=[[UILabel alloc]init];
  156. _priceLabel.font=[UIFont systemFontOfSize:16];
  157. _priceLabel.textColor=[UIColor YHColorWithHex:0x393939];
  158. _priceLabel.text=@"¥---";
  159. }
  160. return _priceLabel;
  161. }
  162. -(UIImageView *)shopImg
  163. {
  164. if (!_shopImg) {
  165. _shopImg =[[UIImageView alloc]init];
  166. [_shopImg setImage:[UIImage imageNamed:@"tm_icon"]];
  167. _shopImg.layer.cornerRadius=3;
  168. _shopImg.layer.masksToBounds=YES;
  169. }
  170. return _shopImg;
  171. }
  172. -(UILabel *)shopLabel
  173. {
  174. if (!_shopLabel) {
  175. _shopLabel=[[UILabel alloc]init];
  176. _shopLabel.text=@"----";
  177. _shopLabel.textColor=[UIColor YHColorWithHex:0x8D8A8A];
  178. _shopLabel.font=[UIFont systemFontOfSize:11];
  179. }
  180. return _shopLabel;
  181. }
  182. -(UIImageView *)quanImgv
  183. {
  184. if (!_quanImgv) {
  185. _quanImgv =[[UIImageView alloc]init];
  186. [_quanImgv setImage:[UIImage imageNamed:@"quan"]];
  187. _quanImgv.layer.cornerRadius=2;
  188. _quanImgv.layer.masksToBounds=YES;
  189. _quanImgv.hidden=YES;
  190. }
  191. return _quanImgv;
  192. }
  193. -(UILabel *)quanLabel
  194. {
  195. if (!_quanLabel) {
  196. _quanLabel=[[UILabel alloc]init];
  197. _quanLabel.textColor=[UIColor YHColorWithHex:0xFF7D00];
  198. _quanLabel.font=[UIFont systemFontOfSize:10];
  199. _quanLabel.textAlignment=NSTextAlignmentCenter;
  200. _quanLabel.text=@"--元";
  201. }
  202. return _quanLabel;
  203. }
  204. -(UILabel *)salesCountL
  205. {
  206. if (!_salesCountL) {
  207. _salesCountL=[[UILabel alloc]init];
  208. _salesCountL.text=@"月销--";
  209. _salesCountL.textColor=[UIColor YHColorWithHex:0xBBB9BB];
  210. _salesCountL.font=[UIFont systemFontOfSize:10];
  211. }
  212. return _salesCountL;
  213. }
  214. -(UILabel *)makeLabel
  215. {
  216. if (!_makeLabel) {
  217. _makeLabel=[[UILabel alloc]init];
  218. _makeLabel.layer.cornerRadius=13;
  219. _makeLabel.layer.masksToBounds=YES;
  220. _makeLabel.backgroundColor=[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFF8300] toColor:[UIColor YHColorWithHex:0xFF5200] withWidth:80];
  221. _makeLabel.font=[UIFont systemFontOfSize:15];
  222. _makeLabel.textColor=[UIColor whiteColor];
  223. _makeLabel.text=@"赚¥--"; _makeLabel.textAlignment=NSTextAlignmentCenter;
  224. NSString *title=@"赚¥--";
  225. NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:title];
  226. [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,1)]; //设置字体字号和字体类别
  227. [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(1,title.length-1)]; //设置字体字号和字体类别
  228. _makeLabel.attributedText=str;
  229. }
  230. return _makeLabel;
  231. }
  232. @end