123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- //
- // DRGoodDetailView.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/1/25.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRGoodDetailView.h"
- #import "DRGoodDetailModel.h"
- #import "DRGotoDetailView.h"
- #import "UIView+SDAutoLayout.h"
- #import "CCCopyLabel.h"
- @interface DRGoodDetailView ()
- @property (nonatomic, strong) CCCopyLabel *goodTitleLabel;
- @property (nonatomic, strong) UILabel *priceLabel;
- @property (nonatomic, strong) UIImageView *discountImageView;
- @property (nonatomic, strong) UILabel *discountPriceLabel;
- @property (nonatomic, strong) UILabel *freePostLabel;
- @property (nonatomic, strong) UILabel *volumeLabel;
- @property (nonatomic, strong) UILabel *quanType;
- @property (nonatomic, strong) UILabel *quanNum;
- //@property (nonatomic, strong) UIImageView
- @end
- @implementation DRGoodDetailView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor whiteColor];
-
- [self initSubviews];
- }
- return self;
- }
- - (void)setGoodModel:(DRGoodDetailModel *)goodModel {
- _goodModel = goodModel;
- if ([goodModel.is_favorites isEqual:@1]) {
- self.collectButton.selected = YES;
- }
- else {
- self.collectButton.selected = NO;
- }
- NSString *quanType = [goodModel.is_coupon boolValue]?@"券":@"折";
- self.quanType.text = quanType;
- NSString *quanNum = [goodModel.is_coupon boolValue]?[NSString stringWithFormat:@"%.2f元",goodModel.coupon_price.floatValue]:[NSString stringWithFormat:@"%.2f折",goodModel.coupon_price.floatValue];
- self.quanNum.text = quanNum;
- self.discountImageView.hidden = ![goodModel.is_coupon boolValue];
-
-
- //标题
- NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
- UIImage *img;
- if ([goodModel.shop_type isEqualToString:@"1"]) {
- img= [UIImage imageNamed:@"tm_shop"];
- }else if([goodModel.shop_type isEqualToString:@"0"]){
- // img= [UIImage imageNamed:@"share_title_tb"];
- }
- if (img) {
- textAttach.image = img;
- textAttach.bounds = CGRectMake(0, -4, img.size.width, img.size.height);
- }
- NSMutableAttributedString *attri;
- if ([goodModel.shop_type isEqualToString:@"1"]) {
- attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",goodModel.title]];
- }else {
- attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",goodModel.title]];
- }
- NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
- [attri insertAttributedString:string atIndex:0];
- NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:8];
- [attri addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
- self.goodTitleLabel.textStr = goodModel.title;
- self.goodTitleLabel.attributedText = attri;
- if (!goodModel.title) {
- self.goodTitleLabel.attributedText = [[NSAttributedString alloc] initWithString:@""];
- }
-
- NSString *priceText = [NSString stringWithFormat:@"原价 ¥%.2f", [goodModel.price floatValue]];
-
- NSUInteger length = [priceText length];
-
- NSMutableAttributedString *attris = [[NSMutableAttributedString alloc] initWithString:priceText];
- [attris addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];
- [attris addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0xA9A9A9] range:NSMakeRange(0, length)];
- [self.priceLabel setAttributedText:attris];
-
-
-
-
- self.discountPriceLabel.text=[NSString stringWithFormat:@"¥%.2f", [goodModel.discount_price floatValue]];
-
- self.volumeLabel.text = [NSString stringWithFormat:@"月销 %ld", goodModel.volume.integerValue];
-
- self.freePostLabel.text = [goodModel.freeShipping isEqual:@1] ? @"包邮" : [NSString stringWithFormat:@"邮费 %@", goodModel.postage];
-
-
-
- }
- - (void)initSubviews {
-
- [self addSubview:self.goodTitleLabel];
- [self addSubview:self.priceLabel];
- [self addSubview:self.discountPriceLabel];
- [self addSubview:self.volumeLabel];
- [self addSubview:self.collectButton];
-
-
- [self makeSubviewsConstraints];
- }
- - (void)makeSubviewsConstraints {
-
-
- [self.discountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(FITSIZE(10));
- make.top.mas_equalTo(Fitsize(15));
- }];
-
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY); make.left.equalTo(self.discountPriceLabel.mas_right).offset(FITSIZE(10));
- }];
-
- [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(FITSIZE(15));
- make.left.equalTo(self.discountPriceLabel);
- make.right.equalTo(self).offset(-FITSIZE(10));
- }];
-
- [self.volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY);
- make.left.equalTo(self.priceLabel.mas_right).offset(FITSIZE(30));
- }];
-
- [self.collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY);
- make.right.equalTo(self).offset(-10);
- make.top.mas_equalTo(Fitsize(15));
- make.width.mas_equalTo(Fitsize(71));
-
- }];
- }
- - (void)couponTapAction:(UIGestureRecognizer *)sender {
- if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapCoupon)]) {
- [self.delegate yh_GoodDetailViewTapCoupon];
- }
- }
- - (void)shopTapAction:(UIGestureRecognizer *)sender {
- if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapShop)]) {
- [self.delegate yh_GoodDetailViewTapShop];
- }
- }
- #pragma mark - lazy
- - (CCCopyLabel *)goodTitleLabel {
- if (!_goodTitleLabel) {
- _goodTitleLabel = [[CCCopyLabel alloc] init];
- _goodTitleLabel.backgroundColor = [UIColor clearColor];
- _goodTitleLabel.textColor = [UIColor YHColorWithHex:0x000000];
-
- _goodTitleLabel.numberOfLines = 2;
- _goodTitleLabel.font=[UIFont boldSystemFontOfSize:FITSIZE(15)];
- }
- return _goodTitleLabel;
- }
- - (UILabel *)priceLabel {
- if (!_priceLabel) {
- _priceLabel = [[UILabel alloc] init];
- _priceLabel.backgroundColor = [UIColor clearColor];
- _priceLabel.textColor = [UIColor YHColorWithHex:0xA9A9A9];
- _priceLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
- }
- return _priceLabel;
- }
- - (UIImageView *)discountImageView {
- if (!_discountImageView) {
- _discountImageView = [[UIImageView alloc] init];
- _discountImageView.backgroundColor = [UIColor clearColor];
- _discountImageView.image = [UIImage imageNamed:@"quan_detail"];
- _discountImageView.hidden=YES;
- }
- return _discountImageView;
- }
- - (UILabel *)discountPriceLabel {
- if (!_discountPriceLabel) {
- _discountPriceLabel = [[UILabel alloc] init];
- _discountPriceLabel.backgroundColor = [UIColor clearColor];
- _discountPriceLabel.textColor = [UIColor YHColorWithHex:0xF5112A];
- _discountPriceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(25)];
- }
- return _discountPriceLabel;
- }
- - (UILabel *)freePostLabel {
- if (!_freePostLabel) {
- _freePostLabel = [[UILabel alloc] init];
- _freePostLabel.backgroundColor = [UIColor clearColor];
- _freePostLabel.textColor = [UIColor YHColorWithHex:0x999999];
- _freePostLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _freePostLabel;
- }
- - (UILabel *)volumeLabel {
- if (!_volumeLabel) {
- _volumeLabel = [[UILabel alloc] init];
- _volumeLabel.backgroundColor = [UIColor clearColor];
- _volumeLabel.textColor = [UIColor YHColorWithHex:0xA9A9A9];
- _volumeLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
- }
- return _volumeLabel;
- }
- - (UILabel *)quanType {
- if (!_quanType) {
- _quanType = [[UILabel alloc] init];
- _quanType.textColor = [UIColor whiteColor];
- _quanType.font = [UIFont boldSystemFontOfSize:10];
- _quanType.textAlignment = NSTextAlignmentCenter;
- }
- return _quanType;
- }
- - (UILabel *)quanNum {
- if (!_quanNum) {
- _quanNum = [[UILabel alloc] init];
- _quanNum.textColor = [UIColor whiteColor];
- _quanNum.font = [UIFont boldSystemFontOfSize:10];
- _quanNum.textAlignment = NSTextAlignmentCenter;
- }
- return _quanNum;
- }
- - (UIButton *)collectButton {
- if (!_collectButton) {
- _collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _collectButton.backgroundColor = [UIColor clearColor];
- [_collectButton setTitleColor:[UIColor YHColorWithHex:0x9B9B9B] forState:UIControlStateNormal];
- _collectButton.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
- [_collectButton setTitle:@"收藏" forState:UIControlStateNormal];
- [_collectButton setImage:[UIImage imageNamed:@"collcection_new"] forState:UIControlStateNormal];
- [_collectButton setImage:[UIImage imageNamed:@"detail_collect_selected"] forState:UIControlStateSelected];
- [_collectButton setButtonStyle:WSLButtonStyleImageLeft spacing:3];
- _collectButton.tag = 1;
- [_collectButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _collectButton;
- }
- -(void)buttonAction:(UIButton *)sender
- {
- if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewCollectButton)]) {
- [self.delegate yh_GoodDetailViewCollectButton];
- }
-
- }
- @end
|