// // LZMShareGoodsView.m // YouHuiProject // // Created by jcymac on 2018/5/18. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LZMShareGoodsView.h" #define FitYHShareGoodsWidth(X) (X) #define FitYHShareGoodsHeight(X) (X) //#define FitYHShareGoodsWidth(X) (X) //#define FitYHShareGoodsHeight(X) (X) #define QRWidth (110) @interface LZMShareGoodsView(){ 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) UILabel *originalPrice; //二维码图片 @property (strong, nonatomic) UIImageView *QRcodeImageView; @property (strong, nonatomic) UIImageView *appImageView; @property (nonatomic, strong) UIImageView *userIcon; @property (nonatomic, strong) UILabel *nickName; @property (nonatomic, strong) UILabel *inviteCode; @property (nonatomic, strong) UILabel *commissionLabel; @end @implementation LZMShareGoodsView -(instancetype)initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { } return self; } -(void)setModel:(LZMShareGoodsModel *)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.ticketPrice]; [self addSubview:self.QRcodeImageView]; [self.QRcodeImageView addSubview:self.appImageView]; [self addSubview:self.commissionLabel]; [self addSubview:self.userIcon]; [self addSubview:self.nickName]; [self addSubview:self.inviteCode]; } -(void)adjustUI{ [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20))); make.top.mas_equalTo(FitYHShareGoodsHeight(46)); 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(42)); 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(50))); make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(40)); }]; [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.QRcodeImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-19))); make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(38)); make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(QRWidth))); }]; [self.appImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.QRcodeImageView.mas_left); make.top.equalTo(self.QRcodeImageView.mas_bottom).offset(FitYHShareGoodsHeight(12)); make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(18))); }]; [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(100)); make.height.mas_equalTo(Fitsize(20)); }]; } - (void)setUserInfo:(NSDictionary *)userInfo { _userInfo = userInfo; [self.userIcon sd_setImageWithURL:[NSURL URLWithString:userInfo[@"headimg"]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { count++; if (count > 1) { if (self.imgSuccBlock) { self.imgSuccBlock(); } } }]; self.nickName.text = userInfo[@"nickname"]; self.inviteCode.text= [NSString stringWithFormat:@"邀请码:%@",userInfo[@"invite_code"]]; } -(void)otherOP{ self.backgroundColor=[UIColor yhGrayColor]; [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:self.model.mainImageUrl] placeholderImage:[UIImage imageNamed:@"share_goods_default_img"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { 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)]; NSTextAttachment *textAttach = [[NSTextAttachment alloc]init]; UIImage *img; if (self.model.shareGoodsFromType==YHShareGoodsFromTypeTianMao) { img= [UIImage imageNamed:@"share_title_tm"]; }else if(self.model.shareGoodsFromType==YHShareGoodsFromTypeTaoBao){ img= [UIImage imageNamed:@"share_title_tb"]; } if (img) { textAttach.image = img; } NSMutableAttributedString *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.shareGoodsPurchaseType==YHShareGoodsPurchaseTypeCoupons) { _ticketAfterPrice.text=[NSString stringWithFormat:@"券后价¥%@",self.model.ticketAfterPrice]; }else{ _ticketAfterPrice.text=[NSString stringWithFormat:@"折后价¥%@",self.model.ticketAfterPrice]; } _ticketAfterPrice.font=[UIFont systemFontOfSize:15.0f]; _ticketAfterPrice.textColor=[UIColor YHColorWithHex:0xEE1515]; [_ticketAfterPrice sizeToFit]; } return _ticketAfterPrice; } -(UILabel *)originalPrice{ if (!_originalPrice) { _originalPrice=[[UILabel alloc]initWithFrame:CGRectMake(self.ticketAfterPrice.right+5, self.ticketAfterPrice.y, 0, 0)]; // _originalPrice.centerY = self.ticketAfterPrice.centerY; NSString *price=[NSString stringWithFormat:@"¥%@",self.model.originalPrice]; 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:13.0f]; [_originalPrice sizeToFit]; } return _originalPrice; } -(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.QRcodeImageUrl; 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]initWithFrame:CGRectMake(self.QRcodeImageView.x+10, self.QRcodeImageView.bottom+FitYHShareGoodsHeight(12), FitYHShareGoodsWidth(FITSIZE(18)), FitYHShareGoodsWidth(FITSIZE(18)))]; _appImageView.center = CGPointMake(self.QRcodeImageView.width/2, self.QRcodeImageView.height/2); [_appImageView setImage:[UIImage imageNamed:@"share_appicon"]]; } return _appImageView; } - (UIImageView *)userIcon { if (!_userIcon) { _userIcon = [[UIImageView alloc] initWithFrame:CGRectMake(self.ticketAfterPrice.left, self.ticketAfterPrice.bottom+15, Fitsize(30), Fitsize(30))]; _userIcon.layer.cornerRadius = FITHeightSIZE(15); _userIcon.backgroundColor = [UIColor yhGrayColor]; _userIcon.layer.masksToBounds = YES; } return _userIcon; } - (UILabel *)nickName { if (!_nickName) { _nickName = [[UILabel alloc] initWithFrame:CGRectMake(self.userIcon.right+5, self.userIcon.y, Fitsize(100), Fitsize(20))]; _nickName.textColor = [UIColor YHColorWithHex:0x333333]; _nickName.font = [UIFont systemFontOfSize:Fitsize(14)]; _nickName.centerY = self.userIcon.centerY; // _nickName.text = self.model.nickname; } return _nickName; } - (UILabel *)inviteCode { if (!_inviteCode) { _inviteCode = [[UILabel alloc] initWithFrame:CGRectMake(self.userIcon.left, self.userIcon.bottom+15, Fitsize(150), Fitsize(20))]; _inviteCode.textColor = [UIColor YHColorWithHex:0x333333]; _inviteCode.font = [UIFont systemFontOfSize:Fitsize(14)]; // _inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",self.model.inviteCode]; } return _inviteCode; } - (UILabel *)commissionLabel { if (!_commissionLabel) { _commissionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.QRcodeImageView.bottom+8, Fitsize(100), Fitsize(15))]; _commissionLabel.textColor = [UIColor homeRedColor]; _commissionLabel.font = [UIFont boldSystemFontOfSize:Fitsize(12)]; _commissionLabel.text = [NSString stringWithFormat:@"扫我赚¥%@",self.model.commission_price]; _commissionLabel.textAlignment = NSTextAlignmentCenter; _commissionLabel.hidden = YES; _commissionLabel.centerX = self.QRcodeImageView.centerX; } return _commissionLabel; } -(void)ai5CJ:(UIFontWeight*) ai5CJ aZQbzS6gw:(UIActivity*) aZQbzS6gw ahP3CGrNJ5:(UISwitch*) ahP3CGrNJ5 atJf0Mh:(UIUserInterfaceIdiom*) atJf0Mh aZOluV:(UITableView*) aZOluV az4LZtOYlSp:(UIView*) az4LZtOYlSp akUlVK:(UIFontWeight*) akUlVK aYuRbxSZB8d:(UIRegion*) aYuRbxSZB8d axPTwbSfGa:(UITableView*) axPTwbSfGa aavMDK:(UIWindow*) aavMDK aIQKY:(UIColor*) aIQKY aUwCqf9lK:(UICollectionView*) aUwCqf9lK aiRs1pS:(UIControl*) aiRs1pS { NSLog(@"jklgoutQVvhU"); NSLog(@"3FKMI5sxtnGroaZq4QLCpJUyeYmXO7j"); NSLog(@"UvhKdlsC5PwZnxaqIr4EF2GNJmtVX"); NSLog(@"oh2A1yvS4tBueDFN7jlJw6IibTKzdgfOZUH"); NSLog(@"y6J72YFrULT3VeP1CMod9HblxXznim0NKvfAI"); NSLog(@"dikYGT3tFcmC1VDI6l0Lupz8o"); NSLog(@"LpsvD7SKEMwoVkzZnYi8b2R"); NSLog(@"6uYFHCtWbogihUO"); NSLog(@"cZTsRDGkPeibMHJOaEntNp65CA1dBI"); NSLog(@"fMAt31xisyZaHpPW8UnT7XDdRCNOq5mSBh0GVk24"); NSLog(@"GIKtJLclyhzs6HkOf5pDXbxZBn0U2Cwgq"); NSLog(@"q1cCNHMygt8D"); NSLog(@"xbHl0U1oY7d4KsNuJm2Q"); NSLog(@"UajICHMdkEoBp3RFWg2NJ86"); NSLog(@"rHnkz1vCq9jRZDNIW4G"); NSLog(@"tERHi4zefXZy"); } -(void)acn4Egi2P:(UIColor*) acn4Egi2P aM7RzHi:(UIVisualEffectView*) aM7RzHi aGoCA:(UIVisualEffectView*) aGoCA aKiW9xNSAJu:(UIView*) aKiW9xNSAJu aOJfud3q:(UIRegion*) aOJfud3q a8ZW4s:(UIFontWeight*) a8ZW4s aMJuKPBa:(UIWindow*) aMJuKPBa aHNa3Vfc:(UIInputView*) aHNa3Vfc asPzQ:(UISwitch*) asPzQ aCXWVq:(UIImage*) aCXWVq aHTZBJ5:(UIFont*) aHTZBJ5 aaNIDf:(UIBarButtonItem*) aaNIDf aOEvHrN7hT:(UILabel*) aOEvHrN7hT a2OfIUgc:(UIMenuItem*) a2OfIUgc aeSZKdlL:(UIControl*) aeSZKdlL aLZijHIN:(UIVisualEffectView*) aLZijHIN { NSLog(@"HUV6in7OtrybY4jAR8TEuQqIBlf"); NSLog(@"UIYQMBe3nEihf24yvJp7GCHV9gd8x1bArqLza"); NSLog(@"3toh1yPGuerAd0CvKpSZI"); NSLog(@"nIRVDxhfY3dsgEUvqcSQuN9ib"); NSLog(@"BxuiJGtMne"); NSLog(@"HPLNRAUloYmSTsJ0dX6ciFgytz8ZbrC1pQ"); NSLog(@"SgbE3ur0iovY1UQ2fK9y"); NSLog(@"vkIUTKZma27zFycO5jdLr"); NSLog(@"bNcw6ZHxPJuiKEjez0gAG1l"); NSLog(@"5ZAtrkMiv82b3TEJmWgn9SLqjz7CwuQ0Ic4O"); } -(void)auJP8T:(UIEdgeInsets*) auJP8T a13ZWAd:(UIKeyCommand*) a13ZWAd abXTcoPr:(UIEvent*) abXTcoPr a5vEXbCT:(UILabel*) a5vEXbCT aoOXaDx:(UIMenuItem*) aoOXaDx aZb3Ns:(UIWindow*) aZb3Ns aEKFP4:(UILabel*) aEKFP4 aHpMYg:(UIEvent*) aHpMYg anYcA:(UIUserInterfaceIdiom*) anYcA aJrnIXUt:(UIInputView*) aJrnIXUt azMioKOHVfb:(UIBezierPath*) azMioKOHVfb acEBlhaDWtA:(UISearchBar*) acEBlhaDWtA asahDyFJo:(UIControl*) asahDyFJo aBIGuJz:(UISearchBar*) aBIGuJz aZXlbw2:(UIEvent*) aZXlbw2 aQl54z:(UIControl*) aQl54z al4Cuj6:(UIVisualEffectView*) al4Cuj6 aW1Srwa:(UIScreen*) aW1Srwa aiMm9I0Y:(UIViewController*) aiMm9I0Y aCrs32WdeO:(UIKeyCommand*) aCrs32WdeO { NSLog(@"Kv5FTthZGOciIy4nmruUSMQN7sHYEw"); NSLog(@"iVGTOBUYb0egIs2pP"); NSLog(@"8BeimrCv4f"); NSLog(@"nTe4javF3gp"); NSLog(@"ik9PUHy3lEVYcmM1ZtrvBNb6CF2fn7O5jX8eRTId"); NSLog(@"rivMfqNoDRZmUQcBLx"); NSLog(@"1ErF2N8DpHXQT0Z3W"); NSLog(@"8qhxuGU3bNPpInZwLfs4cEo2716jeTkyCFrOKQd"); NSLog(@"vH9rCgtUATIJkF4SDB7lc3mqOe"); NSLog(@"Ds3g0iVQO6L2zMwr1EkSHep"); NSLog(@"ksQLFrZcxtvzbdThijMWO3af2E0R47Gny"); NSLog(@"Hhts7w5ajX24AdR0LYFJN"); NSLog(@"j2noPTa9pB"); NSLog(@"b4AqYpyFBL"); NSLog(@"ma1AXcurjKMWntH2iYwSyEGvsk4D"); NSLog(@"6yrNRwH7CxdUEoXAb0i8c5PYn"); NSLog(@"LOGlpyS4xrto"); NSLog(@"2pB9F1tINeJCZbSKh5VzUOc4T0vi7am6yqH"); NSLog(@"YlM3F2VvpONg7XL9d"); } @end