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

DRPopShareGoodView.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. //
  2. // DRPopShareGoodView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/10.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRPopShareGoodView.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 (85)
  15. @interface DRPopShareGoodView()
  16. {
  17. NSInteger count;
  18. }
  19. //主图
  20. @property (strong, nonatomic) UIImageView *mainImageView;
  21. //商品标题
  22. @property (strong, nonatomic) UILabel *titleLabel;
  23. //商品券后价
  24. @property (strong, nonatomic) UILabel *ticketAfterPrice;
  25. //券钱
  26. @property (strong, nonatomic) UILabel *ticketPrice;
  27. //券钱
  28. @property (strong, nonatomic) UIImageView *ticketPriceBackImageView;
  29. //原始价格
  30. @property (strong, nonatomic) UILabel *originalPrice;
  31. //二维码图片
  32. @property (strong, nonatomic) UIImageView *QRcodeImageView;
  33. @property (strong, nonatomic) UIImageView *appImageView;
  34. @property (strong,nonatomic) UILabel *appTitle;
  35. @property (nonatomic, strong) UILabel *quanType;
  36. @property (nonatomic, strong) UILabel *commissionLabel;
  37. @property (nonatomic, strong) UIActivityIndicatorView *indicatorView;
  38. @property (nonatomic, strong) UIImageView *userIcon;
  39. @property (nonatomic, strong) UILabel *nickName;
  40. @property (nonatomic, strong) UILabel *inviteCode;
  41. @end
  42. @implementation DRPopShareGoodView
  43. -(instancetype)initWithFrame:(CGRect)frame{
  44. if (self=[super initWithFrame:frame]) {
  45. }
  46. return self;
  47. }
  48. -(void)setModel:(DRShareInfoModel *)model{
  49. _model=model;
  50. [self addUI];
  51. [self adjustUI];
  52. [self otherOP];
  53. }
  54. -(void)drawRect:(CGRect)rect{
  55. [super drawRect:rect];
  56. }
  57. -(void)addUI{
  58. [self addSubview:self.titleLabel];
  59. [self addSubview:self.mainImageView];
  60. [self addSubview:self.ticketAfterPrice];
  61. [self addSubview:self.originalPrice];
  62. [self addSubview:self.ticketPriceBackImageView];
  63. [self.ticketPriceBackImageView addSubview:self.ticketPrice];
  64. [self.ticketPriceBackImageView addSubview:self.quanType];
  65. [self addSubview:self.QRcodeImageView];
  66. [self addSubview:self.appImageView];
  67. [self addSubview:self.appTitle];
  68. [self addSubview:self.commissionLabel];
  69. [self addSubview:self.indicatorView];
  70. [self.indicatorView startAnimating];
  71. [self addSubview:self.userIcon];
  72. [self addSubview:self.nickName];
  73. [self addSubview:self.inviteCode];
  74. if (!self.model.is_coupon.boolValue) {
  75. self.ticketPrice.hidden=YES;
  76. self.ticketPriceBackImageView.hidden=YES;
  77. }else{
  78. self.ticketPrice.hidden=NO;
  79. self.ticketPriceBackImageView.hidden=NO;
  80. }
  81. }
  82. -(void)adjustUI{
  83. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
  85. make.top.mas_equalTo(FitYHShareGoodsHeight(26));
  86. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
  87. }];
  88. [self.mainImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(20)));
  90. make.top.equalTo(self.titleLabel.mas_bottom).offset(FitYHShareGoodsHeight(22));
  91. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-20)));
  92. make.height.mas_equalTo(FitYHShareGoodsWidth(self.width-2*FITSIZE(20)));
  93. }];
  94. [self.ticketAfterPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(15)));
  96. make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(20));
  97. }];
  98. [self.originalPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.left.mas_equalTo(self.ticketAfterPrice.mas_right).mas_offset(5);
  100. make.centerY.mas_equalTo(self.ticketAfterPrice.mas_centerY);
  101. // make.width.mas_equalTo(FITSIZE(74));
  102. }];
  103. [self.ticketPriceBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.equalTo(self.originalPrice.mas_left);
  105. make.top.mas_equalTo(self.originalPrice.mas_bottom).mas_offset(Fitsize(10));
  106. make.width.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(64)));
  107. make.height.mas_equalTo(FitYHShareGoodsHeight(FITSIZE(14)));
  108. }];
  109. [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.top.bottom.mas_equalTo(0);
  111. make.width.mas_equalTo(Fitsize(20));
  112. }];
  113. [self.ticketPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  114. make.left.mas_equalTo(Fitsize(20));
  115. make.right.top.bottom.mas_equalTo(0);
  116. }];
  117. [self.QRcodeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.right.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(-19)));
  119. make.top.equalTo(self.mainImageView.mas_bottom).offset(FitYHShareGoodsHeight(20));
  120. make.width.height.mas_equalTo(FITSIZE(QRWidth));
  121. }];
  122. [self.appImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
  124. make.centerY.mas_equalTo(self.QRcodeImageView.mas_centerY);
  125. make.width.height.mas_equalTo(FitYHShareGoodsWidth(FITSIZE(18)));
  126. }];
  127. // [self.appTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  128. // make.top.equalTo(self.appImageView.mas_top);
  129. // make.right.equalTo(self.QRcodeImageView.mas_right);
  130. // }];
  131. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.centerX.mas_equalTo(self.QRcodeImageView.mas_centerX);
  133. make.top.mas_equalTo(self.QRcodeImageView.mas_bottom).mas_offset(5);
  134. }];
  135. [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.left.mas_equalTo(self.ticketAfterPrice.mas_left);
  137. make.top.mas_equalTo(self.ticketAfterPrice.mas_bottom).mas_offset(Fitsize(10));
  138. make.width.height.mas_equalTo(Fitsize(30));
  139. }];
  140. [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.left.mas_equalTo(self.userIcon.mas_right).mas_offset(5);
  142. make.centerY.mas_equalTo(self.userIcon.mas_centerY);
  143. make.width.mas_equalTo(Fitsize(100));
  144. make.height.mas_equalTo(Fitsize(20));
  145. }];
  146. [self.inviteCode mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.left.mas_equalTo(self.userIcon.mas_left);
  148. make.top.mas_equalTo(self.userIcon.mas_bottom).mas_equalTo(Fitsize(10));
  149. make.width.mas_equalTo(Fitsize(140));
  150. make.height.mas_equalTo(Fitsize(20));
  151. }];
  152. self.ticketPriceBackImageView.hidden = YES;
  153. }
  154. -(void)otherOP{
  155. self.backgroundColor=[UIColor yhGrayColor];
  156. [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) {
  157. [self.indicatorView stopAnimating];
  158. count++;
  159. if (count>1) {
  160. if (self.imgSuccBlock) {
  161. self.imgSuccBlock();
  162. }
  163. }
  164. }];
  165. }
  166. #pragma mark 懒加载
  167. -(UILabel *)titleLabel{
  168. if (!_titleLabel) {
  169. _titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(20)), FitYHShareGoodsHeight(46), FitYHShareGoodsWidth(self.width-2*FITSIZE(20)), 0)];
  170. _titleLabel.font = [UIFont systemFontOfSize:14];
  171. // NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  172. // UIImage *img;
  173. // if (self.model.shareGoodsFromType==YHShareGoodsFromTypeTianMao) {
  174. // img= [UIImage imageNamed:@"share_title_tm"];
  175. // }else if(self.model.shareGoodsFromType==YHShareGoodsFromTypeTaoBao){
  176. //
  177. // }
  178. // if (img) {
  179. // textAttach.image = img;
  180. // }
  181. // textAttach.bounds = CGRectMake(0, -2, img.size.width*0.7, img.size.height*0.7);
  182. // NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
  183. // NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  184. // [attri insertAttributedString:string atIndex:0];
  185. NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  186. UIImage *img;
  187. if (self.model.shop_type.integerValue == 1) {
  188. img= [UIImage imageNamed:@"tm_shop"];
  189. }
  190. if (img) {
  191. textAttach.image = img;
  192. textAttach.bounds = CGRectMake(0, -2, 15, 15);
  193. }
  194. NSMutableAttributedString *attri;
  195. if (self.model.shop_type.integerValue == 1) {
  196. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.model.title]];
  197. }else {
  198. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",self.model.title]];
  199. }
  200. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  201. [attri insertAttributedString:string atIndex:0];
  202. _titleLabel.attributedText = attri;
  203. // _titleLabel.text=@"虹小型电风扇迷你手持电扇USB学生宿舍 ";
  204. _titleLabel.numberOfLines=2;
  205. [_titleLabel sizeToFit];
  206. }
  207. return _titleLabel;
  208. }
  209. -(UIImageView *)mainImageView{
  210. if (!_mainImageView) {
  211. _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))))];
  212. }
  213. return _mainImageView;
  214. }
  215. -(UILabel *)ticketAfterPrice{
  216. if (!_ticketAfterPrice) {
  217. _ticketAfterPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(15)), self.mainImageView.bottom+FitYHShareGoodsHeight(40), 0, 0)];
  218. if (self.model.is_coupon.boolValue) {
  219. _ticketAfterPrice.text=[NSString stringWithFormat:@"券后¥%.2f",[self.model.discount_price floatValue]];
  220. }else{
  221. _ticketAfterPrice.text=[NSString stringWithFormat:@"折后¥%.2f",[self.model.discount_price floatValue]];
  222. }
  223. _ticketAfterPrice.font=[UIFont systemFontOfSize:14.0f];
  224. _ticketAfterPrice.textColor=[UIColor YHColorWithHex:0xEE1515];
  225. [_ticketAfterPrice sizeToFit];
  226. }
  227. return _ticketAfterPrice;
  228. }
  229. -(UILabel *)originalPrice{
  230. if (!_originalPrice) {
  231. _originalPrice=[[UILabel alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(FITSIZE(14)), self.ticketAfterPrice.bottom+FitYHShareGoodsHeight(14), 0, 0)];
  232. NSString *price=[NSString stringWithFormat:@"%.2f",[self.model.price floatValue]];
  233. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
  234. [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
  235. [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
  236. [_originalPrice setAttributedText:attri];
  237. _originalPrice.textColor=[UIColor YHColorWithHex:0x999999];
  238. _originalPrice.font=[UIFont systemFontOfSize:12.0f];
  239. [_originalPrice sizeToFit];
  240. _originalPrice.centerY = self.ticketAfterPrice.centerY;
  241. }
  242. return _originalPrice;
  243. }
  244. -(UIImageView *)ticketPriceBackImageView{
  245. if (!_ticketPriceBackImageView) {
  246. _ticketPriceBackImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.originalPrice.x, self.originalPrice.bottom+FitYHShareGoodsHeight(22), FitYHShareGoodsWidth(FITSIZE(64)), FitYHShareGoodsHeight(14))];
  247. // _ticketPriceBackImageView.backgroundColor=[UIColor blueColor];
  248. [_ticketPriceBackImageView setImage:[UIImage imageNamed:@"quan_detail"]];
  249. }
  250. return _ticketPriceBackImageView;
  251. }
  252. -(UILabel *)ticketPrice{
  253. if (!_ticketPrice) {
  254. _ticketPrice=[[UILabel alloc]init];
  255. _ticketPrice.textColor=[UIColor whiteColor];
  256. _ticketPrice.text=[NSString stringWithFormat:@"%@元",self.model.coupon_price];
  257. _ticketPrice.font=[UIFont systemFontOfSize:Fitsize(10)];
  258. _ticketPrice.textAlignment=NSTextAlignmentCenter;
  259. }
  260. return _ticketPrice;
  261. }
  262. - (UILabel *)quanType {
  263. if (!_quanType) {
  264. _quanType = [[UILabel alloc] init];
  265. if (self.model.is_coupon.boolValue) {
  266. _quanType.text=@"券";
  267. }else{
  268. _quanType.text=@"折";
  269. }
  270. _quanType.textColor=[UIColor whiteColor];
  271. _quanType.font=[UIFont systemFontOfSize:Fitsize(10)];
  272. _quanType.textAlignment=NSTextAlignmentCenter;
  273. }
  274. return _quanType;
  275. }
  276. - (UILabel *)commissionLabel {
  277. if (!_commissionLabel) {
  278. _commissionLabel = [[UILabel alloc] init];
  279. _commissionLabel.text = [NSString stringWithFormat:@"购买可赚¥%@",self.model.self_commission];
  280. _commissionLabel.textColor = [UIColor homeRedColor];
  281. _commissionLabel.font = [UIFont boldSystemFontOfSize:Fitsize(12)];
  282. _commissionLabel.text = [NSString stringWithFormat:@"扫我赚¥%@",self.model.self_commission];
  283. _commissionLabel.hidden = YES;
  284. }
  285. return _commissionLabel;
  286. }
  287. -(UIImageView *)QRcodeImageView{
  288. if (!_QRcodeImageView) {
  289. _QRcodeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FitYHShareGoodsWidth(self.width-FITSIZE(19)-FITSIZE(QRWidth)), self.mainImageView.bottom+FitYHShareGoodsHeight(38), FitYHShareGoodsWidth(FITSIZE(QRWidth)), FitYHShareGoodsWidth(FITSIZE(QRWidth)))];
  290. //1. 实例化二维码滤镜
  291. CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  292. // 2. 恢复滤镜的默认属性
  293. [filter setDefaults];
  294. // 3. 将字符串转换成NSData
  295. NSString *urlStr =self.model.url;
  296. NSData *data = [urlStr dataUsingEncoding:NSUTF8StringEncoding];
  297. // 4. 通过KVO设置滤镜inputMessage数据
  298. [filter setValue:data forKey:@"inputMessage"];
  299. // 5. 获得滤镜输出的图像
  300. CIImage *outputImage = [filter outputImage];
  301. UIImage *img=[outputImage createNonInterpolatedUIImagewithSize:FITSIZE(QRWidth)];
  302. [_QRcodeImageView setImage:img];
  303. _QRcodeImageView.backgroundColor=[UIColor clearColor];
  304. }
  305. return _QRcodeImageView;
  306. }
  307. -(UIImageView *)appImageView{
  308. if (!_appImageView) {
  309. _appImageView=[[UIImageView alloc]init];
  310. [_appImageView setImage:[UIImage imageNamed:@"share_appicon"]];
  311. }
  312. return _appImageView;
  313. }
  314. -(UILabel *)appTitle{
  315. if (!_appTitle) {
  316. _appTitle=[[UILabel alloc]initWithFrame:CGRectMake(self.appImageView.right, self.appImageView.y, self.QRcodeImageView.right-self.appImageView.right-10,self.appImageView.height )];
  317. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  318. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  319. _appTitle.text=app_Name;
  320. _appTitle.textColor=[UIColor YHColorWithHex:0x666666];
  321. _appTitle.font=[UIFont systemFontOfSize:12.0f];
  322. _appTitle.textAlignment=NSTextAlignmentRight;
  323. }
  324. return _appTitle;
  325. }
  326. - (UIActivityIndicatorView *)indicatorView {
  327. if (!_indicatorView) {
  328. _indicatorView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
  329. _indicatorView.frame= CGRectMake(0, 0, 50, 50);
  330. _indicatorView.color = [UIColor homeRedColor];
  331. _indicatorView.center = CGPointMake(self.width/2, self.height/2);
  332. _indicatorView.hidesWhenStopped = YES;
  333. }
  334. return _indicatorView;
  335. }
  336. - (UIImageView *)userIcon {
  337. if (!_userIcon) {
  338. _userIcon = [[UIImageView alloc] init];
  339. _userIcon.layer.cornerRadius = Fitsize(15);
  340. _userIcon.backgroundColor = [UIColor yhGrayColor];
  341. _userIcon.layer.masksToBounds = YES;
  342. [_userIcon sd_setImageWithURL:[NSURL URLWithString:self.model.userinfo[@"headimg"]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  343. count++;
  344. if (count>1) {
  345. if (self.imgSuccBlock) {
  346. self.imgSuccBlock();
  347. }
  348. }
  349. }];
  350. }
  351. return _userIcon;
  352. }
  353. - (UILabel *)nickName {
  354. if (!_nickName) {
  355. _nickName = [[UILabel alloc] init];
  356. _nickName.textColor = [UIColor YHColorWithHex:0x333333];
  357. _nickName.font = [UIFont systemFontOfSize:Fitsize(14)];
  358. _nickName.text = self.model.userinfo[@"nickname"];
  359. }
  360. return _nickName;
  361. }
  362. - (UILabel *)inviteCode {
  363. if (!_inviteCode) {
  364. _inviteCode = [[UILabel alloc] init];
  365. _inviteCode.textColor = [UIColor YHColorWithHex:0x333333];
  366. _inviteCode.font = [UIFont systemFontOfSize:Fitsize(12)];
  367. _inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",self.model.userinfo[@"invite_code"]];
  368. }
  369. return _inviteCode;
  370. }
  371. @end