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

DRGoodDetailView.m 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. //
  2. // DRGoodDetailView.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRGoodDetailView.h"
  9. #import "DRGoodDetailModel.h"
  10. #import "DRGotoDetailView.h"
  11. #import "UIView+SDAutoLayout.h"
  12. #import "CCCopyLabel.h"
  13. @interface DRGoodDetailView ()
  14. @property (nonatomic, strong) CCCopyLabel *goodTitleLabel;
  15. @property (nonatomic, strong) UILabel *priceLabel;
  16. @property (nonatomic, strong) UIImageView *discountImageView;
  17. @property (nonatomic, strong) UILabel *discountPriceLabel;
  18. @property (nonatomic, strong) UILabel *freePostLabel;
  19. @property (nonatomic, strong) UILabel *volumeLabel;
  20. @property (nonatomic, strong) UILabel *quanType;
  21. @property (nonatomic, strong) UILabel *quanNum;
  22. //@property (nonatomic, strong) UIImageView
  23. @end
  24. @implementation DRGoodDetailView
  25. - (instancetype)initWithFrame:(CGRect)frame {
  26. self = [super initWithFrame:frame];
  27. if (self) {
  28. self.backgroundColor = [UIColor whiteColor];
  29. [self initSubviews];
  30. }
  31. return self;
  32. }
  33. - (void)setGoodModel:(DRGoodDetailModel *)goodModel {
  34. _goodModel = goodModel;
  35. if ([goodModel.is_favorites isEqual:@1]) {
  36. self.collectButton.selected = YES;
  37. }
  38. else {
  39. self.collectButton.selected = NO;
  40. }
  41. NSString *quanType = [goodModel.is_coupon boolValue]?@"券":@"折";
  42. self.quanType.text = quanType;
  43. NSString *quanNum = [goodModel.is_coupon boolValue]?[NSString stringWithFormat:@"%.2f元",goodModel.coupon_price.floatValue]:[NSString stringWithFormat:@"%.2f折",goodModel.coupon_price.floatValue];
  44. self.quanNum.text = quanNum;
  45. self.discountImageView.hidden = ![goodModel.is_coupon boolValue];
  46. //标题
  47. NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  48. UIImage *img;
  49. if ([goodModel.shop_type isEqualToString:@"1"]) {
  50. img= [UIImage imageNamed:@"tm_shop"];
  51. }else if([goodModel.shop_type isEqualToString:@"0"]){
  52. // img= [UIImage imageNamed:@"share_title_tb"];
  53. }
  54. if (img) {
  55. textAttach.image = img;
  56. textAttach.bounds = CGRectMake(0, -4, img.size.width, img.size.height);
  57. }
  58. NSMutableAttributedString *attri;
  59. if ([goodModel.shop_type isEqualToString:@"1"]) {
  60. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",goodModel.title]];
  61. }else {
  62. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",goodModel.title]];
  63. }
  64. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  65. [attri insertAttributedString:string atIndex:0];
  66. NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  67. [paragraphStyle setLineSpacing:8];
  68. [attri addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
  69. self.goodTitleLabel.textStr = goodModel.title;
  70. self.goodTitleLabel.attributedText = attri;
  71. if (!goodModel.title) {
  72. self.goodTitleLabel.attributedText = [[NSAttributedString alloc] initWithString:@""];
  73. }
  74. NSString *priceText = [NSString stringWithFormat:@"原价 ¥%.2f", [goodModel.price floatValue]];
  75. NSUInteger length = [priceText length];
  76. NSMutableAttributedString *attris = [[NSMutableAttributedString alloc] initWithString:priceText];
  77. [attris addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];
  78. [attris addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0xA9A9A9] range:NSMakeRange(0, length)];
  79. [self.priceLabel setAttributedText:attris];
  80. self.discountPriceLabel.text=[NSString stringWithFormat:@"¥%.2f", [goodModel.discount_price floatValue]];
  81. self.volumeLabel.text = [NSString stringWithFormat:@"月销 %ld", goodModel.volume.integerValue];
  82. self.freePostLabel.text = [goodModel.freeShipping isEqual:@1] ? @"包邮" : [NSString stringWithFormat:@"邮费 %@", goodModel.postage];
  83. }
  84. - (void)initSubviews {
  85. [self addSubview:self.goodTitleLabel];
  86. [self addSubview:self.priceLabel];
  87. [self addSubview:self.discountPriceLabel];
  88. [self addSubview:self.volumeLabel];
  89. [self addSubview:self.collectButton];
  90. [self makeSubviewsConstraints];
  91. }
  92. - (void)makeSubviewsConstraints {
  93. [self.discountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.mas_equalTo(FITSIZE(10));
  95. make.top.mas_equalTo(Fitsize(15));
  96. }];
  97. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY); make.left.equalTo(self.discountPriceLabel.mas_right).offset(FITSIZE(10));
  99. }];
  100. [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(FITSIZE(15));
  102. make.left.equalTo(self.discountPriceLabel);
  103. make.right.equalTo(self).offset(-FITSIZE(10));
  104. }];
  105. [self.volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY);
  107. make.left.equalTo(self.priceLabel.mas_right).offset(FITSIZE(30));
  108. }];
  109. [self.collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY);
  111. make.right.equalTo(self).offset(-10);
  112. make.top.mas_equalTo(Fitsize(15));
  113. make.width.mas_equalTo(Fitsize(71));
  114. }];
  115. }
  116. - (void)couponTapAction:(UIGestureRecognizer *)sender {
  117. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapCoupon)]) {
  118. [self.delegate yh_GoodDetailViewTapCoupon];
  119. }
  120. }
  121. - (void)shopTapAction:(UIGestureRecognizer *)sender {
  122. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapShop)]) {
  123. [self.delegate yh_GoodDetailViewTapShop];
  124. }
  125. }
  126. #pragma mark - lazy
  127. - (CCCopyLabel *)goodTitleLabel {
  128. if (!_goodTitleLabel) {
  129. _goodTitleLabel = [[CCCopyLabel alloc] init];
  130. _goodTitleLabel.backgroundColor = [UIColor clearColor];
  131. _goodTitleLabel.textColor = [UIColor YHColorWithHex:0x000000];
  132. _goodTitleLabel.numberOfLines = 2;
  133. _goodTitleLabel.font=[UIFont boldSystemFontOfSize:FITSIZE(15)];
  134. }
  135. return _goodTitleLabel;
  136. }
  137. - (UILabel *)priceLabel {
  138. if (!_priceLabel) {
  139. _priceLabel = [[UILabel alloc] init];
  140. _priceLabel.backgroundColor = [UIColor clearColor];
  141. _priceLabel.textColor = [UIColor YHColorWithHex:0xA9A9A9];
  142. _priceLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
  143. }
  144. return _priceLabel;
  145. }
  146. - (UIImageView *)discountImageView {
  147. if (!_discountImageView) {
  148. _discountImageView = [[UIImageView alloc] init];
  149. _discountImageView.backgroundColor = [UIColor clearColor];
  150. _discountImageView.image = [UIImage imageNamed:@"quan_detail"];
  151. _discountImageView.hidden=YES;
  152. }
  153. return _discountImageView;
  154. }
  155. - (UILabel *)discountPriceLabel {
  156. if (!_discountPriceLabel) {
  157. _discountPriceLabel = [[UILabel alloc] init];
  158. _discountPriceLabel.backgroundColor = [UIColor clearColor];
  159. _discountPriceLabel.textColor = [UIColor YHColorWithHex:0xF5112A];
  160. _discountPriceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(25)];
  161. }
  162. return _discountPriceLabel;
  163. }
  164. - (UILabel *)freePostLabel {
  165. if (!_freePostLabel) {
  166. _freePostLabel = [[UILabel alloc] init];
  167. _freePostLabel.backgroundColor = [UIColor clearColor];
  168. _freePostLabel.textColor = [UIColor YHColorWithHex:0x999999];
  169. _freePostLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  170. }
  171. return _freePostLabel;
  172. }
  173. - (UILabel *)volumeLabel {
  174. if (!_volumeLabel) {
  175. _volumeLabel = [[UILabel alloc] init];
  176. _volumeLabel.backgroundColor = [UIColor clearColor];
  177. _volumeLabel.textColor = [UIColor YHColorWithHex:0xA9A9A9];
  178. _volumeLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
  179. }
  180. return _volumeLabel;
  181. }
  182. - (UILabel *)quanType {
  183. if (!_quanType) {
  184. _quanType = [[UILabel alloc] init];
  185. _quanType.textColor = [UIColor whiteColor];
  186. _quanType.font = [UIFont boldSystemFontOfSize:10];
  187. _quanType.textAlignment = NSTextAlignmentCenter;
  188. }
  189. return _quanType;
  190. }
  191. - (UILabel *)quanNum {
  192. if (!_quanNum) {
  193. _quanNum = [[UILabel alloc] init];
  194. _quanNum.textColor = [UIColor whiteColor];
  195. _quanNum.font = [UIFont boldSystemFontOfSize:10];
  196. _quanNum.textAlignment = NSTextAlignmentCenter;
  197. }
  198. return _quanNum;
  199. }
  200. - (UIButton *)collectButton {
  201. if (!_collectButton) {
  202. _collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
  203. _collectButton.backgroundColor = [UIColor clearColor];
  204. [_collectButton setTitleColor:[UIColor YHColorWithHex:0x9B9B9B] forState:UIControlStateNormal];
  205. _collectButton.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
  206. [_collectButton setTitle:@"收藏" forState:UIControlStateNormal];
  207. [_collectButton setImage:[UIImage imageNamed:@"collcection_new"] forState:UIControlStateNormal];
  208. [_collectButton setImage:[UIImage imageNamed:@"detail_collect_selected"] forState:UIControlStateSelected];
  209. [_collectButton setButtonStyle:WSLButtonStyleImageLeft spacing:3];
  210. _collectButton.tag = 1;
  211. [_collectButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  212. }
  213. return _collectButton;
  214. }
  215. -(void)buttonAction:(UIButton *)sender
  216. {
  217. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewCollectButton)]) {
  218. [self.delegate yh_GoodDetailViewCollectButton];
  219. }
  220. }
  221. @end