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

DRShareGoodsView.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // DRShareGoodsView.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/5/18.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRShareGoodsView.h"
  9. #import "PhoneLoginManager.h"
  10. #define FitYHShareGoodsWidth(X) (X)
  11. #define FitYHShareGoodsHeight(X) (X)
  12. //#define FitYHShareGoodsWidth(X) (X)
  13. //#define FitYHShareGoodsHeight(X) (X)
  14. #define QRWidth (110)
  15. @interface DRShareGoodsView(){
  16. NSInteger count;
  17. }
  18. //主图
  19. @property (strong, nonatomic) UIImageView *mainImageView;
  20. //商品标题
  21. @property (strong, nonatomic) UILabel *titleLabel;
  22. //商品券后价
  23. @property (strong, nonatomic) UILabel *ticketAfterPrice;
  24. //券钱
  25. @property (strong, nonatomic) UILabel *ticketPrice;
  26. //券钱
  27. //原始价格
  28. @property (strong, nonatomic) UILabel *originalPrice;
  29. //二维码图片
  30. @property (strong, nonatomic) UIImageView *QRcodeImageView;
  31. @property (strong, nonatomic) UIImageView *appImageView;
  32. @property (nonatomic, strong) UIImageView *userIcon;
  33. @property (nonatomic, strong) UILabel *nickName;
  34. @property (nonatomic, strong) UILabel *inviteCode;
  35. @property (nonatomic, strong) UILabel *commissionLabel;
  36. @end
  37. @implementation DRShareGoodsView
  38. -(instancetype)initWithFrame:(CGRect)frame{
  39. if (self=[super initWithFrame:frame]) {
  40. }
  41. return self;
  42. }
  43. -(void)setModel:(DRShareGoodsModel *)model{
  44. _model=model;
  45. [self addUI];
  46. [self adjustUI];
  47. [self otherOP];
  48. }
  49. -(void)drawRect:(CGRect)rect{
  50. [super drawRect:rect];
  51. }
  52. -(void)addUI{
  53. [self addSubview:self.titleLabel];
  54. [self addSubview:self.mainImageView];
  55. [self addSubview:self.ticketAfterPrice];
  56. [self addSubview:self.originalPrice];
  57. [self addSubview:self.ticketPrice];
  58. [self addSubview:self.QRcodeImageView];
  59. [self.QRcodeImageView addSubview:self.appImageView];
  60. [self addSubview:self.commissionLabel];
  61. [self addSubview:self.userIcon];
  62. [self addSubview:self.nickName];
  63. [self addSubview:self.inviteCode];
  64. }
  65. -(void)adjustUI{
  66. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
  68. make.top.mas_equalTo(FitYHShareGoodsHeight(46));
  69. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
  70. }];
  71. [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
  73. make.top.equalTo(self.titleLabel.mas_bottom).offset(FitYHShareGoodsHeight(42));
  74. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
  75. make.height.mas_equalTo(FitYHShareGoodsWidth(self.width-2*FITSIZE(20)));
  76. }];
  77. [self.ticketAfterPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(50)));
  79. make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(40));
  80. }];
  81. [self.originalPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.mas_equalTo(self.ticketAfterPrice.mas_right).mas_offset(5);
  83. make.centerY.mas_equalTo(self.ticketAfterPrice.mas_centerY);
  84. // make.width.mas_equalTo(FITSIZE(74));
  85. }];
  86. [self.QRcodeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-19)));
  88. make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(38));
  89. make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(QRWidth)));
  90. }];
  91. [self.appImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.equalTo(self.QRcodeImageView.mas_left);
  93. make.top.equalTo(self.QRcodeImageView.mas_bottom).offset(FitYHShareGoodsHeight(12));
  94. make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(18)));
  95. }];
  96. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
  98. make.top.mas_equalTo(self.QRcodeImageView.mas_bottom).mas_offset(5);
  99. }];
  100. [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.left.mas_equalTo(self.ticketAfterPrice.mas_left);
  102. make.top.mas_equalTo(self.ticketAfterPrice.mas_bottom).mas_offset(Fitsize(10));
  103. make.width.height.mas_equalTo(Fitsize(30));
  104. }];
  105. [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.mas_equalTo(self.userIcon.mas_right).mas_offset(5);
  107. make.centerY.mas_equalTo(self.userIcon.mas_centerY);
  108. make.width.mas_equalTo(Fitsize(100));
  109. make.height.mas_equalTo(Fitsize(20));
  110. }];
  111. [self.inviteCode mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.mas_equalTo(self.userIcon.mas_left);
  113. make.top.mas_equalTo(self.userIcon.mas_bottom).mas_equalTo(Fitsize(10));
  114. make.width.mas_equalTo(Fitsize(100));
  115. make.height.mas_equalTo(Fitsize(20));
  116. }];
  117. }
  118. - (void)setUserInfo:(NSDictionary *)userInfo {
  119. _userInfo = userInfo;
  120. [self.userIcon sd_setImageWithURL:[NSURL URLWithString:userInfo[@"headimg"]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  121. count++;
  122. if (count > 1) {
  123. if (self.imgSuccBlock) {
  124. self.imgSuccBlock();
  125. }
  126. }
  127. }];
  128. self.nickName.text = userInfo[@"nickname"];
  129. self.inviteCode.text= [NSString stringWithFormat:@"邀请码:%@",userInfo[@"invite_code"]];
  130. }
  131. -(void)otherOP{
  132. self.backgroundColor=[UIColor yhGrayColor];
  133. [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) {
  134. count++;
  135. if (count > 1) {
  136. if (self.imgSuccBlock) {
  137. self.imgSuccBlock();
  138. }
  139. }
  140. }];
  141. }
  142. #pragma mark 懒加载
  143. -(UILabel *)titleLabel{
  144. if (!_titleLabel) {
  145. _titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(20)), FitYHShareGoodsHeight(46), FitYHShareGoodsWidth(self.width-2*FITSIZE(20)), 0)];
  146. NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  147. UIImage *img;
  148. if (self.model.shareGoodsFromType==YHShareGoodsFromTypeTianMao) {
  149. img= [UIImage imageNamed:@"share_title_tm"];
  150. }else if(self.model.shareGoodsFromType==YHShareGoodsFromTypeTaoBao){
  151. img= [UIImage imageNamed:@"share_title_tb"];
  152. }
  153. if (img) {
  154. textAttach.image = img;
  155. }
  156. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
  157. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  158. [attri insertAttributedString:string atIndex:0];
  159. _titleLabel.attributedText = attri;
  160. // _titleLabel.text=@"虹小型电风扇迷你手持电扇USB学生宿舍 ";
  161. _titleLabel.numberOfLines=2;
  162. [_titleLabel sizeToFit];
  163. }
  164. return _titleLabel;
  165. }
  166. -(UIImageView *)mainImageView{
  167. if (!_mainImageView) {
  168. _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))))];
  169. }
  170. return _mainImageView;
  171. }
  172. -(UILabel *)ticketAfterPrice{
  173. if (!_ticketAfterPrice) {
  174. _ticketAfterPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(15)), self.mainImageView.bottom+FitYHShareGoodsHeight(40), 0, 0)];
  175. if (self.model.shareGoodsPurchaseType==YHShareGoodsPurchaseTypeCoupons) {
  176. _ticketAfterPrice.text=[NSString stringWithFormat:@"券后价¥%@",self.model.ticketAfterPrice];
  177. }else{
  178. _ticketAfterPrice.text=[NSString stringWithFormat:@"折后价¥%@",self.model.ticketAfterPrice];
  179. }
  180. _ticketAfterPrice.font=[UIFont systemFontOfSize:15.0f];
  181. _ticketAfterPrice.textColor=[UIColor YHColorWithHex:0xEE1515];
  182. [_ticketAfterPrice sizeToFit];
  183. }
  184. return _ticketAfterPrice;
  185. }
  186. -(UILabel *)originalPrice{
  187. if (!_originalPrice) {
  188. _originalPrice=[[UILabel alloc]initWithFrame:CGRectMake(self.ticketAfterPrice.right+5, self.ticketAfterPrice.y, 0, 0)];
  189. // _originalPrice.centerY = self.ticketAfterPrice.centerY;
  190. NSString *price=[NSString stringWithFormat:@"¥%@",self.model.originalPrice];
  191. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
  192. [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
  193. [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
  194. [_originalPrice setAttributedText:attri];
  195. _originalPrice.textColor=[UIColor YHColorWithHex:0x999999];
  196. _originalPrice.font=[UIFont systemFontOfSize:13.0f];
  197. [_originalPrice sizeToFit];
  198. }
  199. return _originalPrice;
  200. }
  201. -(UIImageView *)QRcodeImageView{
  202. if (!_QRcodeImageView) {
  203. _QRcodeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(self.width-FITSIZE(19)-FITSIZE(QRWidth)), self.mainImageView.bottom+FitYHShareGoodsHeight(38), FitYHShareGoodsWidth(FITSIZE(QRWidth)), FitYHShareGoodsWidth(FITSIZE(QRWidth)))];
  204. //1. 实例化二维码滤镜
  205. CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  206. // 2. 恢复滤镜的默认属性
  207. [filter setDefaults];
  208. // 3. 将字符串转换成NSData
  209. NSString *urlStr =self.model.QRcodeImageUrl;
  210. NSData *data = [urlStr dataUsingEncoding:NSUTF8StringEncoding];
  211. // 4. 通过KVO设置滤镜inputMessage数据
  212. [filter setValue:data forKey:@"inputMessage"];
  213. // 5. 获得滤镜输出的图像
  214. CIImage *outputImage = [filter outputImage];
  215. UIImage *img=[outputImage createNonInterpolatedUIImagewithSize:FITSIZE(QRWidth)];
  216. [_QRcodeImageView setImage:img];
  217. _QRcodeImageView.backgroundColor=[UIColor clearColor];
  218. }
  219. return _QRcodeImageView;
  220. }
  221. -(UIImageView *)appImageView{
  222. if (!_appImageView) {
  223. _appImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.QRcodeImageView.x+10, self.QRcodeImageView.bottom+FitYHShareGoodsHeight(12), FitYHShareGoodsWidth(FITSIZE(18)), FitYHShareGoodsWidth(FITSIZE(18)))];
  224. _appImageView.center = CGPointMake(self.QRcodeImageView.width/2, self.QRcodeImageView.height/2);
  225. [_appImageView setImage:[UIImage imageNamed:@"share_appicon"]];
  226. }
  227. return _appImageView;
  228. }
  229. - (UIImageView *)userIcon {
  230. if (!_userIcon) {
  231. _userIcon = [[UIImageView alloc] initWithFrame:CGRectMake(self.ticketAfterPrice.left, self.ticketAfterPrice.bottom+15, Fitsize(30), Fitsize(30))];
  232. _userIcon.layer.cornerRadius = Fitsize(15);
  233. _userIcon.backgroundColor = [UIColor yhGrayColor];
  234. _userIcon.layer.masksToBounds = YES;
  235. }
  236. return _userIcon;
  237. }
  238. - (UILabel *)nickName {
  239. if (!_nickName) {
  240. _nickName = [[UILabel alloc] initWithFrame:CGRectMake(self.userIcon.right+5, self.userIcon.y, Fitsize(100), Fitsize(20))];
  241. _nickName.textColor = [UIColor YHColorWithHex:0x333333];
  242. _nickName.font = [UIFont systemFontOfSize:Fitsize(14)];
  243. _nickName.centerY = self.userIcon.centerY;
  244. // _nickName.text = self.model.nickname;
  245. }
  246. return _nickName;
  247. }
  248. - (UILabel *)inviteCode {
  249. if (!_inviteCode) {
  250. _inviteCode = [[UILabel alloc] initWithFrame:CGRectMake(self.userIcon.left, self.userIcon.bottom+15, Fitsize(150), Fitsize(20))];
  251. _inviteCode.textColor = [UIColor YHColorWithHex:0x333333];
  252. _inviteCode.font = [UIFont systemFontOfSize:Fitsize(14)];
  253. // _inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",self.model.inviteCode];
  254. }
  255. return _inviteCode;
  256. }
  257. - (UILabel *)commissionLabel {
  258. if (!_commissionLabel) {
  259. _commissionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.QRcodeImageView.bottom+8, Fitsize(100), Fitsize(15))];
  260. _commissionLabel.textColor = [UIColor homeRedColor];
  261. _commissionLabel.font = [UIFont boldSystemFontOfSize:Fitsize(12)];
  262. _commissionLabel.text = [NSString stringWithFormat:@"扫我赚¥%@",self.model.commission_price];
  263. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  264. _commissionLabel.hidden = YES;
  265. _commissionLabel.centerX = self.QRcodeImageView.centerX;
  266. }
  267. return _commissionLabel;
  268. }
  269. @end