123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- //
- // YHGoodDetailView.m
- // YouHuiProject
- //
- // Created by xiaoxi on 2018/1/25.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "YHGoodDetailView.h"
- #import "YHGoodDetailModel.h"
- @interface YHGoodDetailView ()
- @property (nonatomic, strong) UILabel *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) UIImageView *couponImageView;
- @property (nonatomic, strong) UILabel *couponPriceLabel;
- @property (nonatomic, strong) UILabel *couponTimeLabel;
- @property (nonatomic, strong) UILabel *couponGetLabel;
- @property (nonatomic, strong) CALayer *middleLineLayer;
- @property (nonatomic, strong) UIView *middleView;
- @property (nonatomic, strong) UIImageView *shopImageView;
- @property (nonatomic, strong) UILabel *shopTitleLabel;
- @property (nonatomic, strong) UIImageView *viewShopRightImageView;
- @property (nonatomic, strong) UILabel *viewShopLabel;
- @property (nonatomic, strong) CALayer *bottomLineLayer;
- @property (nonatomic, strong) UIView *bottomView;
- @property (nonatomic, strong) UIButton *goodIntro;
- @property (nonatomic, strong) UIButton *shopService;
- @property (nonatomic, strong) UIButton *postService;
- @end
- @implementation YHGoodDetailView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor whiteColor];
-
- [self initSubviews];
- }
- return self;
- }
- - (void)setGoodModel:(YHGoodDetailModel *)goodModel {
- _goodModel = goodModel;
-
- self.goodTitleLabel.text = goodModel.title;
- self.priceLabel.text = [NSString stringWithFormat:@"原价 ¥%@", goodModel.price];
- self.discountPriceLabel.text = [NSString stringWithFormat:@"¥%@", goodModel.discount_price];
- self.volumeLabel.text = [NSString stringWithFormat:@"月销 %@", goodModel.volume];
- self.freePostLabel.text = [goodModel.freeShipping isEqual:@1] ? @"包邮" : [NSString stringWithFormat:@"邮费 %@", goodModel.postage];
- self.couponPriceLabel.text = [NSString stringWithFormat:@"%@元优惠券", goodModel.coupon_price];
- self.couponTimeLabel.text = [NSString stringWithFormat:@"使用期限:%@-%@", goodModel.start_time, goodModel.end_time];
- [self.shopImageView yy_setImageWithURL:[NSURL URLWithString:goodModel.shop_pict_url] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
- self.shopTitleLabel.text = goodModel.shop_title;
- [self.goodIntro setTitle:[NSString stringWithFormat:@"宝贝描述:%@", goodModel.item_score] forState:UIControlStateNormal];
- [self.shopService setTitle:[NSString stringWithFormat:@"卖家服务:%@", goodModel.service_score] forState:UIControlStateNormal];
- [self.postService setTitle:[NSString stringWithFormat:@"物流服务:%@", goodModel.delivery_score] forState:UIControlStateNormal];
- }
- - (void)initSubviews {
- [self.layer addSublayer:self.middleLineLayer];
- [self.layer addSublayer:self.bottomLineLayer];
-
- [self addSubview:self.goodTitleLabel];
- [self addSubview:self.priceLabel];
- [self addSubview:self.discountImageView];
- [self addSubview:self.discountPriceLabel];
- [self addSubview:self.volumeLabel];
- [self addSubview:self.freePostLabel];
- [self addSubview:self.couponImageView];
- [self.couponImageView addSubview:self.couponPriceLabel];
- [self.couponImageView addSubview:self.couponTimeLabel];
- [self.couponImageView addSubview:self.couponGetLabel];
- [self addSubview:self.middleView];
- [self.middleView addSubview:self.shopImageView];
- [self.middleView addSubview:self.shopTitleLabel];
- [self.middleView addSubview:self.viewShopRightImageView];
- [self.middleView addSubview:self.viewShopLabel];
- [self addSubview:self.bottomView];
- [self.bottomView addSubview:self.goodIntro];
- [self.bottomView addSubview:self.shopService];
- [self.bottomView addSubview:self.postService];
-
- [self makeSubviewsConstraints];
- }
- - (void)makeSubviewsConstraints {
- [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(FITSIZE(20));
- make.top.equalTo(self).offset(FITSIZE(15));
- make.right.equalTo(self).offset(-FITSIZE(20));
- }];
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.goodTitleLabel);
- make.top.equalTo(self.goodTitleLabel.mas_bottom).offset(FITSIZE(15));
- }];
- [self.discountImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.priceLabel);
- make.bottom.equalTo(self.discountPriceLabel).offset(-FITSIZE(3));
- make.size.mas_equalTo(CGSizeMake(FITSIZE(FITSIZE(34)), FITSIZE(12)));
- }];
- [self.discountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.discountImageView.mas_right).offset(FITSIZE(10));
- make.top.equalTo(self.priceLabel.mas_bottom).offset(FITSIZE(10));
- }];
- [self.volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self).offset(-FITSIZE(20));
- make.bottom.equalTo(self.discountImageView);
- }];
- [self.freePostLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.volumeLabel.mas_left).offset(-FITSIZE(10));
- make.bottom.equalTo(self.volumeLabel);
- }];
- [self.couponImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.top.equalTo(self.discountPriceLabel.mas_bottom).offset(FITSIZE(16));
- make.size.mas_equalTo(CGSizeMake(FITSIZE(335), FITSIZE(88)));
- }];
- [self.couponPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.couponImageView);
- make.centerY.equalTo(self.couponImageView).offset(-FITSIZE(10));
- make.width.mas_equalTo(FITSIZE(216));
- }];
- [self.couponTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.couponImageView);
- make.centerY.equalTo(self.couponImageView).offset(FITSIZE(10));
- make.width.mas_equalTo(FITSIZE(216));
- }];
- [self.couponGetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.couponImageView);
- make.centerY.equalTo(self.couponImageView);
- make.width.mas_equalTo(FITSIZE(118));
- }];
- [self.middleView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self);
- make.top.equalTo(self).offset(FITSIZE(214));
- make.right.equalTo(self);
- make.height.mas_equalTo(FITSIZE(100));
- }];
- [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.middleView).offset(FITSIZE(20));
- make.top.equalTo(self.middleView).offset(FITSIZE(22));
- make.size.mas_equalTo(CGSizeMake(FITSIZE(60), FITSIZE(60)));
- }];
- [self.shopTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.shopImageView.mas_right).offset(FITSIZE(14));
- make.centerY.equalTo(self.middleView);
- }];
- [self.viewShopRightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.middleView).offset(-FITSIZE(20));
- make.centerY.equalTo(self.shopTitleLabel);
- make.size.mas_equalTo(CGSizeMake(FITSIZE(20), FITSIZE(20)));
- }];
- [self.viewShopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.viewShopRightImageView.mas_left);
- make.centerY.equalTo(self.shopTitleLabel);
- }];
- [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self);
- make.top.equalTo(self).offset(FITSIZE(319));
- make.right.equalTo(self);
- make.height.mas_equalTo(FITSIZE(40));
- }];
- [self.goodIntro mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bottomView);
- make.top.equalTo(self.bottomView);
- make.width.mas_equalTo(kScreenWidth/3);
- make.bottom.equalTo(self.bottomView);
- }];
- [self.shopService mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.goodIntro.mas_right);
- make.top.equalTo(self.goodIntro);
- make.width.equalTo(self.goodIntro);
- make.bottom.equalTo(self.goodIntro);
- }];
- [self.postService mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.shopService.mas_right);
- make.top.equalTo(self.shopService);
- make.width.equalTo(self.shopService);
- make.bottom.equalTo(self.shopService);
- }];
- }
- - (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
- - (CALayer *)middleLineLayer {
- if (!_middleLineLayer) {
- _middleLineLayer = [CALayer layer];
- _middleLineLayer.frame = CGRectMake(0, FITSIZE(214), kScreenWidth, FITSIZE(5));
- _middleLineLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
- }
- return _middleLineLayer;
- }
- - (CALayer *)bottomLineLayer {
- if (!_bottomLineLayer) {
- _bottomLineLayer = [CALayer layer];
- _bottomLineLayer.frame = CGRectMake(0, FITSIZE(319), kScreenWidth, 0.5);
- _bottomLineLayer.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4].CGColor;
- }
- return _bottomLineLayer;
- }
- - (UILabel *)goodTitleLabel {
- if (!_goodTitleLabel) {
- _goodTitleLabel = [[UILabel alloc] init];
- _goodTitleLabel.backgroundColor = [UIColor clearColor];
- _goodTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
- _goodTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
- }
- return _goodTitleLabel;
- }
- - (UILabel *)priceLabel {
- if (!_priceLabel) {
- _priceLabel = [[UILabel alloc] init];
- _priceLabel.backgroundColor = [UIColor clearColor];
- _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
- _priceLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _priceLabel;
- }
- - (UIImageView *)discountImageView {
- if (!_discountImageView) {
- _discountImageView = [[UIImageView alloc] init];
- _discountImageView.backgroundColor = [UIColor clearColor];
- _discountImageView.image = [UIImage imageNamed:@"couponPrice"];
- }
- return _discountImageView;
- }
- - (UILabel *)discountPriceLabel {
- if (!_discountPriceLabel) {
- _discountPriceLabel = [[UILabel alloc] init];
- _discountPriceLabel.backgroundColor = [UIColor clearColor];
- _discountPriceLabel.textColor = [UIColor YHColorWithHex:0xff2420];
- _discountPriceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(18)];
- }
- 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:0x999999];
- _volumeLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _volumeLabel;
- }
- - (UIImageView *)couponImageView {
- if (!_couponImageView) {
- _couponImageView = [[UIImageView alloc] init];
- _couponImageView.backgroundColor = [UIColor clearColor];
- _couponImageView.image = [UIImage imageNamed:@"cintend_voucher"];
- _couponImageView.userInteractionEnabled = YES;
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(couponTapAction:)];
- [_couponImageView addGestureRecognizer:tap];
- }
- return _couponImageView;
- }
- - (UILabel *)couponPriceLabel {
- if (!_couponPriceLabel) {
- _couponPriceLabel = [[UILabel alloc] init];
- _couponPriceLabel.backgroundColor = [UIColor clearColor];
- _couponPriceLabel.textColor = [UIColor whiteColor];
- _couponPriceLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(16)];
- _couponPriceLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _couponPriceLabel;
- }
- - (UILabel *)couponTimeLabel {
- if (!_couponTimeLabel) {
- _couponTimeLabel = [[UILabel alloc] init];
- _couponTimeLabel.backgroundColor = [UIColor clearColor];
- _couponTimeLabel.textColor = [UIColor whiteColor];
- _couponTimeLabel.font = [UIFont systemFontOfSize:FITSIZE(10)];
- _couponTimeLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _couponTimeLabel;
- }
- - (UILabel *)couponGetLabel {
- if (!_couponGetLabel) {
- _couponGetLabel = [[UILabel alloc] init];
- _couponGetLabel.backgroundColor = [UIColor clearColor];
- _couponGetLabel.textColor = [UIColor whiteColor];
- _couponGetLabel.font = [UIFont boldSystemFontOfSize:FITSIZE(14)];
- _couponGetLabel.text = @"立即领券";
- _couponGetLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _couponGetLabel;
- }
- - (UIView *)middleView {
- if (!_middleView) {
- _middleView = [[UIView alloc] init];
- _middleView.backgroundColor = [UIColor clearColor];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shopTapAction:)];
- [_middleView addGestureRecognizer:tap];
- }
- return _middleView;
- }
- - (UIImageView *)shopImageView {
- if (!_shopImageView) {
- _shopImageView = [[UIImageView alloc] init];
- _shopImageView.backgroundColor = [UIColor clearColor];
- _shopImageView.layer.borderColor = [UIColor YHColorWithHex:0xdddddd].CGColor;
- _shopImageView.layer.borderWidth = 0.5f;
- }
- return _shopImageView;
- }
- - (UILabel *)shopTitleLabel {
- if (!_shopTitleLabel) {
- _shopTitleLabel = [[UILabel alloc] init];
- _shopTitleLabel.backgroundColor = [UIColor clearColor];
- _shopTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
- _shopTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
- }
- return _shopTitleLabel;
- }
- - (UIImageView *)viewShopRightImageView {
- if (!_viewShopRightImageView) {
- _viewShopRightImageView = [[UIImageView alloc] init];
- _viewShopRightImageView.backgroundColor = [UIColor clearColor];
- _viewShopRightImageView.image = [UIImage imageNamed:@"goto"];
- }
- return _viewShopRightImageView;
- }
- - (UILabel *)viewShopLabel {
- if (!_viewShopLabel) {
- _viewShopLabel = [[UILabel alloc] init];
- _viewShopLabel.backgroundColor = [UIColor clearColor];
- _viewShopLabel.textColor = [UIColor YHColorWithHex:0x999999];
- _viewShopLabel.font = [UIFont systemFontOfSize:FITSIZE(12)];
- _viewShopLabel.text = @"查看店铺所有优惠";
- }
- return _viewShopLabel;
- }
- - (UIView *)bottomView {
- if (!_bottomView) {
- _bottomView = [[UIView alloc] init];
- _bottomView.backgroundColor = [UIColor clearColor];
- for (NSInteger i=0; i<3; i++) {
- CALayer *layer = [CALayer layer];
- layer.frame = CGRectMake(kScreenWidth/3*i, FITSIZE(40)/2-FITSIZE(5)/2, 1, FITSIZE(5));
- layer.backgroundColor = [UIColor YHColorWithHex:0x999999].CGColor;
- [_bottomView.layer addSublayer:layer];
- }
- }
- return _bottomView;
- }
- - (UIButton *)goodIntro {
- if (!_goodIntro) {
- _goodIntro = [UIButton buttonWithType:UIButtonTypeCustom];
- _goodIntro.backgroundColor = [UIColor clearColor];
- [_goodIntro setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
- _goodIntro.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _goodIntro;
- }
- - (UIButton *)shopService {
- if (!_shopService) {
- _shopService = [UIButton buttonWithType:UIButtonTypeCustom];
- _shopService.backgroundColor = [UIColor clearColor];
- [_shopService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
- _shopService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _shopService;
- }
- - (UIButton *)postService {
- if (!_postService) {
- _postService = [UIButton buttonWithType:UIButtonTypeCustom];
- _postService.backgroundColor = [UIColor clearColor];
- [_postService setTitleColor:[UIColor YHColorWithHex:0x333333] forState:UIControlStateNormal];
- _postService.titleLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
- }
- return _postService;
- }
- @end
|