口袋优选

KBGoodsCommunityCell.m 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // KBGoodsCommunityCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/9.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBGoodsCommunityCell.h"
  9. @interface KBGoodsCommunityCell ()
  10. @property (nonatomic, strong) UIImageView *icon;
  11. @property (nonatomic, strong) UILabel *nickName;
  12. @property (nonatomic, strong) UILabel *tagLb;
  13. @property (nonatomic, strong) UILabel *desLb;
  14. @property (nonatomic, strong) UIImageView *goodIcon;
  15. @property (nonatomic, strong) YYLabel *title;
  16. @property (nonatomic, strong) YYLabel *priceLb;
  17. @property (nonatomic, strong) YYLabel *disPrice;
  18. @property (nonatomic, strong) UILabel *ticketNum;
  19. @end
  20. @implementation KBGoodsCommunityCell
  21. - (instancetype)initWithFrame:(CGRect)frame
  22. {
  23. self = [super initWithFrame:frame];
  24. if (self) {
  25. self.layer.cornerRadius = 6;
  26. self.backgroundColor = [UIColor whiteColor];
  27. [self initSubViews];
  28. }
  29. return self;
  30. }
  31. - (void)initSubViews {
  32. [self.contentView addSubview:self.icon];
  33. [self.contentView addSubview:self.nickName];
  34. [self.contentView addSubview:self.tagLb];
  35. [self.contentView addSubview:self.goodIcon];
  36. [self.contentView addSubview:self.desLb];
  37. [self.contentView addSubview:self.title];
  38. [self.contentView addSubview:self.priceLb];
  39. [self.contentView addSubview:self.disPrice];
  40. [self.contentView addSubview:self.ticketNum];
  41. [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(5);
  43. make.top.mas_equalTo(8);
  44. make.width.height.mas_equalTo(44);
  45. }];
  46. [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.mas_equalTo(self.icon.mas_right).mas_offset(7);
  48. make.top.mas_equalTo(self.icon).mas_offset(3);
  49. }];
  50. [self.desLb mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.mas_equalTo(self.nickName);
  52. make.bottom.mas_equalTo(self.icon).mas_offset(-3);
  53. }];
  54. [self.tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(self.nickName.mas_right).mas_offset(10);
  56. make.centerY.mas_equalTo(self.nickName.mas_centerY);
  57. make.height.mas_equalTo(16);
  58. }];
  59. [self.goodIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.mas_equalTo(self.icon.mas_bottom).mas_offset(15);
  61. make.left.mas_equalTo(self.icon);
  62. make.width.height.mas_equalTo(100);
  63. }];
  64. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_equalTo(self.goodIcon);
  66. make.left.mas_equalTo(self.goodIcon.mas_right).mas_offset(8);
  67. make.right.mas_equalTo(-15);
  68. }];
  69. [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.mas_equalTo(self.title);
  71. make.bottom.mas_equalTo(self.goodIcon.mas_bottom).mas_offset(-3);
  72. }];
  73. [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(self.disPrice);
  75. make.bottom.mas_equalTo(self.disPrice.mas_top).mas_offset(-8);
  76. }];
  77. [self.ticketNum mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.bottom.mas_equalTo(self.goodIcon);
  79. make.right.mas_equalTo(-15);
  80. make.width.mas_equalTo(70);
  81. make.height.mas_equalTo(25);
  82. }];
  83. }
  84. - (void)setModel:(KBChildGoodModel *)model {
  85. [self.icon sd_setImageWithURL:[NSURL URLWithString:model.userinfo[@"headimg"]]];
  86. self.nickName.text = model.userinfo[@"nick"];
  87. NSString *tag = model.userinfo[@"savelevel"];
  88. CGSize size = [PublicFunction getAutoWidthWith:tag andSize:CGSizeMake(MAXFLOAT, 16) andFont:11];
  89. if (tag.length > 0) {
  90. self.tagLb.text = tag;
  91. [self.tagLb mas_updateConstraints:^(MASConstraintMaker *make) {
  92. make.width.mas_equalTo(size.width+20);
  93. }];
  94. self.tagLb.hidden = NO;
  95. }else {
  96. self.tagLb.hidden = YES;
  97. }
  98. self.desLb.text = model.userinfo[@"desc"];
  99. [self.goodIcon sd_setImageWithURL:[NSURL URLWithString:model.img]];
  100. //标题
  101. UIImage *img;
  102. if ([model.shop_type isEqualToString:@"1"]) {
  103. img= [UIImage imageNamed:@"tm_shop"];
  104. }
  105. YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
  106. if ([model.shop_type isEqualToString:@"1"]) {
  107. imgeView.frame = CGRectMake(0, 0, 15, 15);
  108. }else {
  109. imgeView.frame = CGRectMake(0, 0, 0, 0);
  110. }
  111. NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
  112. NSMutableAttributedString *attri;
  113. if ([model.shop_type isEqualToString:@"1"]) {
  114. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.title]];
  115. }else {
  116. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
  117. }
  118. [attri insertAttributedString:mua atIndex:0];
  119. attri.yy_font = [UIFont systemFontOfSize:14];
  120. attri.yy_color = [UIColor YHColorWithHex:0x444444];
  121. attri.yy_lineSpacing = 4;
  122. self.title.attributedText = attri;
  123. //券后价格
  124. NSString *disStr;
  125. if ([model.is_coupon boolValue]) {
  126. disStr = [NSString stringWithFormat:@"券后¥%.2f", [model.discount_price floatValue]];
  127. }else {
  128. disStr = [NSString stringWithFormat:@"折后¥%.2f", [model.discount_price floatValue]];
  129. }
  130. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  131. [disAttr yy_setFont:[UIFont systemFontOfSize:13] range:NSMakeRange(0, 3)];
  132. [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, disStr.length-3)];
  133. disAttr.yy_color = [UIColor homeRedColor];
  134. self.disPrice.attributedText = disAttr;
  135. //原价
  136. NSString *price = [NSString stringWithFormat:@"原价¥%.2f",[model.price floatValue]];
  137. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price];
  138. attrStr.yy_font = [UIFont systemFontOfSize:11];
  139. attrStr.yy_color = [UIColor YHColorWithHex:0x999999];
  140. YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(1) color:[UIColor YHColorWithHex:0x999999]];
  141. [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(3, price.length-3)];
  142. self.priceLb.attributedText = attrStr;
  143. self.ticketNum.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
  144. self.ticketNum.hidden = ![model.is_coupon boolValue];
  145. }
  146. #pragma mark -----
  147. - (UIImageView *)icon {
  148. if (!_icon) {
  149. _icon = [[UIImageView alloc] init];
  150. _icon.backgroundColor = [UIColor yhGrayColor];
  151. _icon.layer.cornerRadius = 22;
  152. _icon.layer.masksToBounds = YES;
  153. }
  154. return _icon;
  155. }
  156. - (UILabel *)nickName {
  157. if (!_nickName) {
  158. _nickName = [[UILabel alloc] init];
  159. _nickName.font = [UIFont systemFontOfSize:16];
  160. _nickName.textColor = [UIColor YHColorWithHex:0x333333];
  161. }
  162. return _nickName;
  163. }
  164. - (UILabel *)tagLb {
  165. if (!_tagLb) {
  166. _tagLb = [[UILabel alloc] init];
  167. _tagLb.font = [UIFont systemFontOfSize:11];
  168. _tagLb.textColor = [UIColor homeRedColor];
  169. _tagLb.layer.cornerRadius = 8;
  170. _tagLb.layer.borderColor = [UIColor homeRedColor].CGColor;
  171. _tagLb.layer.borderWidth = 1;
  172. _tagLb.textAlignment = NSTextAlignmentCenter;
  173. }
  174. return _tagLb;
  175. }
  176. - (UILabel *)desLb {
  177. if (!_desLb) {
  178. _desLb = [[UILabel alloc] init];
  179. _desLb.textColor = [UIColor YHColorWithHex:0x878585];
  180. _desLb.font = [UIFont systemFontOfSize:13];
  181. }
  182. return _desLb;
  183. }
  184. - (UIImageView *)goodIcon {
  185. if (!_goodIcon) {
  186. _goodIcon = [[UIImageView alloc] init];
  187. _goodIcon.backgroundColor = [UIColor yhGrayColor];
  188. _goodIcon.layer.cornerRadius = 6;
  189. }
  190. return _goodIcon;
  191. }
  192. - (YYLabel *)title {
  193. if (!_title) {
  194. _title = [[YYLabel alloc] init];
  195. _title.font = [UIFont systemFontOfSize:13];
  196. _title.displaysAsynchronously = YES;
  197. _title.numberOfLines = 2;
  198. _title.preferredMaxLayoutWidth = SCREEN_WIDTH-150;
  199. }
  200. return _title;
  201. }
  202. - (YYLabel *)disPrice {
  203. if (!_disPrice) {
  204. _disPrice = [[YYLabel alloc] init];
  205. _disPrice.displaysAsynchronously = YES;
  206. }
  207. return _disPrice;
  208. }
  209. - (YYLabel *)priceLb {
  210. if (!_priceLb) {
  211. _priceLb = [[YYLabel alloc] init];
  212. _priceLb.textColor = [UIColor YHColorWithHex:0xA2A0A0];
  213. _priceLb.font = [UIFont systemFontOfSize:12];
  214. _priceLb.displaysAsynchronously = YES;
  215. }
  216. return _priceLb;
  217. }
  218. - (UILabel *)ticketNum {
  219. if (!_ticketNum) {
  220. _ticketNum = [[UILabel alloc] init];
  221. _ticketNum.backgroundColor = [UIColor homeRedColor];
  222. _ticketNum.font = [UIFont systemFontOfSize:13];
  223. _ticketNum.textAlignment = NSTextAlignmentCenter;
  224. _ticketNum.textColor = [UIColor whiteColor];
  225. _ticketNum.layer.cornerRadius = 4;
  226. _ticketNum.layer.masksToBounds = YES;
  227. }
  228. return _ticketNum;
  229. }
  230. @end