123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- //
- // DRPopShareGoodView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/10.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRPopShareGoodView.h"
- #import "PhoneLoginManager.h"
- #define FitYHShareGoodsWidth(X) (X)
- #define FitYHShareGoodsHeight(X) (X)
- //#define FitYHShareGoodsWidth(X) (X)
- //#define FitYHShareGoodsHeight(X) (X)
- #define QRWidth (85)
- @interface DRPopShareGoodView()
- {
- NSInteger count;
- }
- //主图
- @property (strong, nonatomic) UIImageView *mainImageView;
- //商品标题
- @property (strong, nonatomic) UILabel *titleLabel;
- //商品券后价
- @property (strong, nonatomic) UILabel *ticketAfterPrice;
- //券钱
- @property (strong, nonatomic) UILabel *ticketPrice;
- //券钱
- @property (strong, nonatomic) UIImageView *ticketPriceBackImageView;
- //原始价格
- @property (strong, nonatomic) UILabel *originalPrice;
- //二维码图片
- @property (strong, nonatomic) UIImageView *QRcodeImageView;
- @property (strong, nonatomic) UIImageView *appImageView;
- @property (strong,nonatomic) UILabel *appTitle;
- @property (nonatomic, strong) UILabel *quanType;
- @property (nonatomic, strong) UILabel *commissionLabel;
- @property (nonatomic, strong) UIActivityIndicatorView *indicatorView;
- @property (nonatomic, strong) UIImageView *userIcon;
- @property (nonatomic, strong) UILabel *nickName;
- @property (nonatomic, strong) UILabel *inviteCode;
- @end
- @implementation DRPopShareGoodView
- -(instancetype)initWithFrame:(CGRect)frame{
- if (self=[super initWithFrame:frame]) {
- }
- return self;
- }
- -(void)setModel:(DRShareInfoModel *)model{
- _model=model;
- [self addUI];
- [self adjustUI];
- [self otherOP];
- }
- -(void)drawRect:(CGRect)rect{
- [super drawRect:rect];
- }
- -(void)addUI{
- [self addSubview:self.titleLabel];
- [self addSubview:self.mainImageView];
- [self addSubview:self.ticketAfterPrice];
- [self addSubview:self.originalPrice];
- [self addSubview:self.ticketPriceBackImageView];
- [self.ticketPriceBackImageView addSubview:self.ticketPrice];
- [self.ticketPriceBackImageView addSubview:self.quanType];
- [self addSubview:self.QRcodeImageView];
- [self addSubview:self.appImageView];
- [self addSubview:self.appTitle];
- [self addSubview:self.commissionLabel];
- [self addSubview:self.indicatorView];
- [self.indicatorView startAnimating];
- [self addSubview:self.userIcon];
- [self addSubview:self.nickName];
- [self addSubview:self.inviteCode];
-
- if (!self.model.is_coupon.boolValue) {
- self.ticketPrice.hidden=YES;
- self.ticketPriceBackImageView.hidden=YES;
- }else{
- self.ticketPrice.hidden=NO;
- self.ticketPriceBackImageView.hidden=NO;
- }
- }
- -(void)adjustUI{
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
- make.top.mas_equalTo(FitYHShareGoodsHeight(26));
- make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
- }];
- [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
- make.top.equalTo(self.titleLabel.mas_bottom).offset(FitYHShareGoodsHeight(22));
- make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
- make.height.mas_equalTo(FitYHShareGoodsWidth(self.width-2*FITSIZE(20)));
- }];
-
- [self.ticketAfterPrice mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(15)));
- make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(20));
- }];
- [self.originalPrice mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.ticketAfterPrice.mas_right).mas_offset(5);
- make.centerY.mas_equalTo(self.ticketAfterPrice.mas_centerY);
- // make.width.mas_equalTo(FITSIZE(74));
- }];
- [self.ticketPriceBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.originalPrice.mas_left);
- make.top.mas_equalTo(self.originalPrice.mas_bottom).mas_offset(Fitsize(10));
- make.width.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(64)));
- make.height.mas_equalTo(FitYHShareGoodsHeight(FITSIZE(14)));
- }];
-
- [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.mas_equalTo(0);
- make.width.mas_equalTo(Fitsize(20));
- }];
-
- [self.ticketPrice mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(Fitsize(20));
- make.right.top.bottom.mas_equalTo(0);
- }];
- [self.QRcodeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-19)));
- make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(20));
- make.width.height.mas_equalTo(FITSIZE(QRWidth));
- }];
- [self.appImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
- make.centerY.mas_equalTo(self.QRcodeImageView.mas_centerY);
- make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(18)));
- }];
- // [self.appTitle mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self.appImageView.mas_top);
- // make.right.equalTo(self.QRcodeImageView.mas_right);
- // }];
-
- [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
- make.top.mas_equalTo(self.QRcodeImageView.mas_bottom).mas_offset(5);
- }];
-
- [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.ticketAfterPrice.mas_left);
- make.top.mas_equalTo(self.ticketAfterPrice.mas_bottom).mas_offset(Fitsize(10));
- make.width.height.mas_equalTo(Fitsize(30));
- }];
- [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.userIcon.mas_right).mas_offset(5);
- make.centerY.mas_equalTo(self.userIcon.mas_centerY);
- make.width.mas_equalTo(Fitsize(100));
- make.height.mas_equalTo(Fitsize(20));
- }];
-
- [self.inviteCode mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.userIcon.mas_left);
- make.top.mas_equalTo(self.userIcon.mas_bottom).mas_equalTo(Fitsize(10));
- make.width.mas_equalTo(Fitsize(140));
- make.height.mas_equalTo(Fitsize(20));
- }];
-
-
- self.ticketPriceBackImageView.hidden = YES;
- }
- -(void)otherOP{
- self.backgroundColor=[UIColor yhGrayColor];
- [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:self.model.img] placeholderImage:[UIImage imageNamed:@"share_goods_default_img"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- [self.indicatorView stopAnimating];
- count++;
- if (count>1) {
- if (self.imgSuccBlock) {
- self.imgSuccBlock();
- }
- }
-
- }];
-
- }
- #pragma mark 懒加载
- -(UILabel *)titleLabel{
- if (!_titleLabel) {
- _titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(20)), FitYHShareGoodsHeight(46), FitYHShareGoodsWidth(self.width-2*FITSIZE(20)), 0)];
- _titleLabel.font = [UIFont systemFontOfSize:14];
- // NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
- // UIImage *img;
- // if (self.model.shareGoodsFromType==YHShareGoodsFromTypeTianMao) {
- // img= [UIImage imageNamed:@"share_title_tm"];
- // }else if(self.model.shareGoodsFromType==YHShareGoodsFromTypeTaoBao){
- //
- // }
- // if (img) {
- // textAttach.image = img;
- // }
- // textAttach.bounds = CGRectMake(0, -2, img.size.width*0.7, img.size.height*0.7);
- // NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
- // NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
- // [attri insertAttributedString:string atIndex:0];
- NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
- UIImage *img;
-
- if (self.model.shop_type.integerValue == 1) {
- img= [UIImage imageNamed:@"tm_shop"];
- }
- if (img) {
- textAttach.image = img;
- textAttach.bounds = CGRectMake(0, -2, 15, 15);
- }
-
- NSMutableAttributedString *attri;
- if (self.model.shop_type.integerValue == 1) {
- attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
- }else {
- attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",self.model.title]];
- }
-
- NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
- [attri insertAttributedString:string atIndex:0];
- _titleLabel.attributedText = attri;
- // _titleLabel.text=@"虹小型电风扇迷你手持电扇USB学生宿舍 ";
- _titleLabel.numberOfLines=2;
- [_titleLabel sizeToFit];
- }
- return _titleLabel;
- }
- -(UIImageView *)mainImageView{
- if (!_mainImageView) {
- _mainImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(20)), self.titleLabel.bottom+FitYHShareGoodsHeight(42), FitYHShareGoodsWidth(self.width-2*FITSIZE(20)), FitYHShareGoodsWidth((self.width-2*FITSIZE(20))))];
- }
- return _mainImageView;
- }
- -(UILabel *)ticketAfterPrice{
- if (!_ticketAfterPrice) {
- _ticketAfterPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(15)), self.mainImageView.bottom+FitYHShareGoodsHeight(40), 0, 0)];
- if (self.model.is_coupon.boolValue) {
- _ticketAfterPrice.text=[NSString stringWithFormat:@"券后¥%.2f",[self.model.discount_price floatValue]];
- }else{
- _ticketAfterPrice.text=[NSString stringWithFormat:@"折后¥%.2f",[self.model.discount_price floatValue]];
- }
-
- _ticketAfterPrice.font=[UIFont systemFontOfSize:14.0f];
- _ticketAfterPrice.textColor=[UIColor YHColorWithHex:0xEE1515];
- [_ticketAfterPrice sizeToFit];
-
- }
- return _ticketAfterPrice;
- }
- -(UILabel *)originalPrice{
- if (!_originalPrice) {
- _originalPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(14)), self.ticketAfterPrice.bottom+FitYHShareGoodsHeight(14), 0, 0)];
- NSString *price=[NSString stringWithFormat:@"%.2f",[self.model.price floatValue]];
- NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
- [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
- [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
- [_originalPrice setAttributedText:attri];
- _originalPrice.textColor=[UIColor YHColorWithHex:0x999999];
- _originalPrice.font=[UIFont systemFontOfSize:12.0f];
- [_originalPrice sizeToFit];
- _originalPrice.centerY = self.ticketAfterPrice.centerY;
- }
- return _originalPrice;
- }
- -(UIImageView *)ticketPriceBackImageView{
- if (!_ticketPriceBackImageView) {
- _ticketPriceBackImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.originalPrice.x, self.originalPrice.bottom+FitYHShareGoodsHeight(22), FitYHShareGoodsWidth(FITSIZE(64)), FitYHShareGoodsHeight(14))];
- // _ticketPriceBackImageView.backgroundColor=[UIColor blueColor];
- [_ticketPriceBackImageView setImage:[UIImage imageNamed:@"quan_detail"]];
- }
- return _ticketPriceBackImageView;
- }
- -(UILabel *)ticketPrice{
- if (!_ticketPrice) {
-
-
- _ticketPrice=[[UILabel alloc]init];
- _ticketPrice.textColor=[UIColor whiteColor];
- _ticketPrice.text=[NSString stringWithFormat:@"%@元",self.model.coupon_price];
- _ticketPrice.font=[UIFont systemFontOfSize:Fitsize(10)];
- _ticketPrice.textAlignment=NSTextAlignmentCenter;
- }
- return _ticketPrice;
- }
- - (UILabel *)quanType {
- if (!_quanType) {
- _quanType = [[UILabel alloc] init];
- if (self.model.is_coupon.boolValue) {
- _quanType.text=@"券";
- }else{
- _quanType.text=@"折";
- }
- _quanType.textColor=[UIColor whiteColor];
- _quanType.font=[UIFont systemFontOfSize:Fitsize(10)];
- _quanType.textAlignment=NSTextAlignmentCenter;
- }
- return _quanType;
- }
- - (UILabel *)commissionLabel {
- if (!_commissionLabel) {
- _commissionLabel = [[UILabel alloc] init];
- _commissionLabel.text = [NSString stringWithFormat:@"购买可赚¥%@",self.model.self_commission];
- _commissionLabel.textColor = [UIColor homeRedColor];
- _commissionLabel.font = [UIFont boldSystemFontOfSize:Fitsize(12)];
- _commissionLabel.text = [NSString stringWithFormat:@"扫我赚¥%@",self.model.self_commission];
- _commissionLabel.hidden = YES;
- }
- return _commissionLabel;
- }
- -(UIImageView *)QRcodeImageView{
- if (!_QRcodeImageView) {
-
- _QRcodeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(self.width-FITSIZE(19)-FITSIZE(QRWidth)), self.mainImageView.bottom+FitYHShareGoodsHeight(38), FitYHShareGoodsWidth(FITSIZE(QRWidth)), FitYHShareGoodsWidth(FITSIZE(QRWidth)))];
- //1. 实例化二维码滤镜
- CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
- // 2. 恢复滤镜的默认属性
- [filter setDefaults];
- // 3. 将字符串转换成NSData
- NSString *urlStr =self.model.url;
- NSData *data = [urlStr dataUsingEncoding:NSUTF8StringEncoding];
- // 4. 通过KVO设置滤镜inputMessage数据
- [filter setValue:data forKey:@"inputMessage"];
- // 5. 获得滤镜输出的图像
- CIImage *outputImage = [filter outputImage];
- UIImage *img=[outputImage createNonInterpolatedUIImagewithSize:FITSIZE(QRWidth)];
- [_QRcodeImageView setImage:img];
- _QRcodeImageView.backgroundColor=[UIColor clearColor];
- }
- return _QRcodeImageView;
- }
- -(UIImageView *)appImageView{
- if (!_appImageView) {
-
- _appImageView=[[UIImageView alloc]init];
- [_appImageView setImage:[UIImage imageNamed:@"share_appicon"]];
- }
- return _appImageView;
- }
- -(UILabel *)appTitle{
- if (!_appTitle) {
- _appTitle=[[UILabel alloc]initWithFrame:CGRectMake(self.appImageView.right, self.appImageView.y, self.QRcodeImageView.right-self.appImageView.right-10,self.appImageView.height )];
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
- _appTitle.text=app_Name;
- _appTitle.textColor=[UIColor YHColorWithHex:0x666666];
- _appTitle.font=[UIFont systemFontOfSize:12.0f];
- _appTitle.textAlignment=NSTextAlignmentRight;
- }
- return _appTitle;
- }
- - (UIActivityIndicatorView *)indicatorView {
- if (!_indicatorView) {
- _indicatorView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
- _indicatorView.frame= CGRectMake(0, 0, 50, 50);
- _indicatorView.color = [UIColor homeRedColor];
- _indicatorView.center = CGPointMake(self.width/2, self.height/2);
- _indicatorView.hidesWhenStopped = YES;
- }
- return _indicatorView;
- }
- - (UIImageView *)userIcon {
- if (!_userIcon) {
- _userIcon = [[UIImageView alloc] init];
- _userIcon.layer.cornerRadius = Fitsize(15);
- _userIcon.backgroundColor = [UIColor yhGrayColor];
- _userIcon.layer.masksToBounds = YES;
- [_userIcon sd_setImageWithURL:[NSURL URLWithString:self.model.userinfo[@"headimg"]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- count++;
- if (count>1) {
- if (self.imgSuccBlock) {
- self.imgSuccBlock();
- }
- }
- }];
- }
- return _userIcon;
- }
- - (UILabel *)nickName {
- if (!_nickName) {
- _nickName = [[UILabel alloc] init];
- _nickName.textColor = [UIColor YHColorWithHex:0x333333];
- _nickName.font = [UIFont systemFontOfSize:Fitsize(14)];
- _nickName.text = self.model.userinfo[@"nickname"];
- }
- return _nickName;
- }
- - (UILabel *)inviteCode {
- if (!_inviteCode) {
- _inviteCode = [[UILabel alloc] init];
- _inviteCode.textColor = [UIColor YHColorWithHex:0x333333];
- _inviteCode.font = [UIFont systemFontOfSize:Fitsize(12)];
- _inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",self.model.userinfo[@"invite_code"]];
- }
- return _inviteCode;
- }
- @end
|