天天省钱快报

KBShareGetFriendsView.m 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // KBShareGetFriendsView.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/5/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. //#define QRwidth (120)
  9. #import "KBShareGetFriendsView.h"
  10. @interface KBShareGetFriendsView()
  11. {
  12. NSInteger count;
  13. }
  14. @property(nonatomic,strong)UIImageView *centerImageView;
  15. @property(nonatomic,strong)UIImageView *yhIconImageView;
  16. @property(nonatomic,strong)UILabel *yhTitleLabel;
  17. @property(nonatomic,strong)UILabel *getFirendCodeLabel;
  18. @property(nonatomic,strong)UIImageView *QRcodeImageView;
  19. @property(nonatomic,strong)UILabel *bottomLabel;
  20. @property(nonatomic,strong)UIImageView *userIcon;
  21. @property(nonatomic,strong)UILabel *nickName;
  22. @property(nonatomic,strong)UILabel *inviteCode;
  23. @end
  24. @implementation KBShareGetFriendsView
  25. static NSInteger QRwidth;
  26. -(instancetype)initWithFrame:(CGRect)frame{
  27. if (self=[super initWithFrame:frame]) {
  28. if (iPhone6) {
  29. QRwidth=100;
  30. }else if(iPhone5){
  31. QRwidth=80;
  32. }else{
  33. QRwidth=120;
  34. }
  35. }
  36. return self;
  37. }
  38. -(void)setModel:(KBShareGetFriendsModel *)model{
  39. _model=model;
  40. [self addUI];
  41. [self otherOP];
  42. }
  43. -(void)addUI{
  44. [self addSubview:self.centerImageView];
  45. [self addSubview:self.yhIconImageView];
  46. [self addSubview:self.yhTitleLabel];
  47. // [self addSubview:self.getFirendCodeLabel];
  48. [self addSubview:self.QRcodeImageView];
  49. [self addSubview:self.bottomLabel];
  50. [self addSubview:self.inviteCode];
  51. [self addSubview:self.userIcon];
  52. [self addSubview:self.nickName];
  53. }
  54. - (void)setUserinfo:(NSDictionary *)userinfo {
  55. _userinfo = userinfo;
  56. self.inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",userinfo[@"invite_code"]];
  57. [self.userIcon sd_setImageWithURL:[NSURL URLWithString:userinfo[@"headimg"]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  58. count++;
  59. if (count > 1) {
  60. if (self.imgSuccBlock) {
  61. self.imgSuccBlock();
  62. }
  63. }
  64. }];
  65. self.nickName.text = userinfo[@"nickname"];
  66. }
  67. -(void)otherOP{
  68. if (self.model.imgUrl) {//url存在
  69. [self.centerImageView sd_setImageWithURL:[NSURL URLWithString:self.model.imgUrl] placeholderImage:[UIImage imageNamed:@""] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  70. if (self.model.headimg.length > 0) {
  71. [self.userIcon sd_setImageWithURL:[NSURL URLWithString:self.model.headimg] placeholderImage:[UIImage imageNamed:@"lgoin"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  72. if (self.imgSuccBlock) {
  73. self.imgSuccBlock();
  74. }
  75. }];
  76. }else {
  77. count++;
  78. if (count > 1) {
  79. if (self.imgSuccBlock) {
  80. self.imgSuccBlock();
  81. }
  82. }
  83. }
  84. }];
  85. }else if(self.model.img) {//img存在
  86. [self.centerImageView setImage:self.model.img];
  87. [self.userIcon sd_setImageWithURL:[NSURL URLWithString:self.model.headimg] placeholderImage:[UIImage imageNamed:@"lgoin"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  88. if (self.imgSuccBlock) {
  89. self.imgSuccBlock();
  90. }
  91. }];
  92. }else{
  93. if (self.imgSuccBlock) {
  94. self.imgSuccBlock();
  95. }
  96. }
  97. }
  98. -(UIImageView *)centerImageView{
  99. if (!_centerImageView) {// (self.width-FITSIZE(44))*(425.0f/330.0f)
  100. _centerImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(22), FITHeightSIZE(64),self.width-FITSIZE(44), FITHeightSIZE(425))];
  101. _centerImageView.contentMode=UIViewContentModeScaleAspectFit;
  102. _centerImageView.backgroundColor=[UIColor clearColor];
  103. }
  104. return _centerImageView;
  105. }
  106. - (UIImageView *)yhIconImageView{
  107. if (!_yhIconImageView) {
  108. _yhIconImageView=[[UIImageView alloc]initWithFrame:CGRectMake(FITSIZE(30), self.inviteCode.bottom+FITHeightSIZE(15), 22, 22)];
  109. [_yhIconImageView setImage:[UIImage imageNamed:@"share_appicon"]];
  110. }
  111. return _yhIconImageView;
  112. }
  113. - (UILabel *)yhTitleLabel{
  114. if (!_yhTitleLabel) {
  115. _yhTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.yhIconImageView.right+FITSIZE(11), 0, 0, 0)];
  116. _yhTitleLabel.textColor=[UIColor YHColorWithHex:0x333333];
  117. _yhTitleLabel.font=[UIFont systemFontOfSize:14];
  118. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  119. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
  120. _yhTitleLabel.text=app_Name;
  121. [_yhTitleLabel sizeToFit];
  122. _yhTitleLabel.centerY=self.yhIconImageView.centerY;
  123. }
  124. return _yhTitleLabel;
  125. }
  126. - (UILabel *)getFirendCodeLabel{
  127. if (!_getFirendCodeLabel) {
  128. _getFirendCodeLabel=[[UILabel alloc]initWithFrame:CGRectMake(self.yhTitleLabel.right+20, self.yhIconImageView.bottom+15, 0, 0)];
  129. _getFirendCodeLabel.font=[UIFont systemFontOfSize:14];
  130. _getFirendCodeLabel.textColor=[UIColor YHColorWithHex:0x262626];
  131. _getFirendCodeLabel.text=[NSString stringWithFormat:@"选的对 赚得多"];
  132. [_getFirendCodeLabel sizeToFit];
  133. _getFirendCodeLabel.centerY = self.yhIconImageView.centerY;
  134. }
  135. return _getFirendCodeLabel;
  136. }
  137. - (UIImageView *)QRcodeImageView{
  138. if (!_QRcodeImageView) {
  139. _QRcodeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.width-FITSIZE((30+QRwidth)), self.centerImageView.bottom+28, FITSIZE(QRwidth), FITSIZE(QRwidth))];
  140. //1. 实例化二维码滤镜
  141. CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
  142. // 2. 恢复滤镜的默认属性
  143. [filter setDefaults];
  144. // 3. 将字符串转换成NSData
  145. NSString *urlStr =@"http://www.ourname.xin";
  146. if (self.model.QRcodeUrl) {
  147. urlStr=self.model.QRcodeUrl;
  148. }
  149. NSData *data = [urlStr dataUsingEncoding:NSUTF8StringEncoding];
  150. // 4. 通过KVO设置滤镜inputMessage数据
  151. [filter setValue:data forKey:@"inputMessage"];
  152. // 5. 获得滤镜输出的图像
  153. CIImage *outputImage = [filter outputImage];
  154. UIImage *img=[outputImage createNonInterpolatedUIImagewithSize:FITSIZE(QRwidth)];
  155. [_QRcodeImageView setImage:img];
  156. _QRcodeImageView.backgroundColor=[UIColor yhGrayColor];
  157. }
  158. return _QRcodeImageView;
  159. }
  160. - (UILabel *)bottomLabel{
  161. if (!_bottomLabel) {
  162. _bottomLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, self.height-37, self.width, 37)];
  163. _bottomLabel.text=@"1.微信扫码下载 →2.微信登录 →3.开启优选之旅";
  164. [_bottomLabel adjustsFontSizeToFitWidth];
  165. _bottomLabel.textAlignment=NSTextAlignmentCenter;
  166. _bottomLabel.backgroundColor=[UIColor YHColorWithHex:0xF2F2F2];
  167. _bottomLabel.textColor=[UIColor YHColorWithHex:0x666666];
  168. _bottomLabel.font=[UIFont systemFontOfSize:14];
  169. }
  170. return _bottomLabel;
  171. }
  172. - (UIImageView *)userIcon {
  173. if (!_userIcon) {
  174. _userIcon = [[UIImageView alloc] initWithFrame:CGRectMake(Fitsize(30), self.centerImageView.bottom+28, FITHeightSIZE(30), FITHeightSIZE(30))];
  175. _userIcon.layer.cornerRadius = FITHeightSIZE(15);
  176. _userIcon.backgroundColor = [UIColor yhGrayColor];
  177. _userIcon.layer.masksToBounds = YES;
  178. }
  179. return _userIcon;
  180. }
  181. - (UILabel *)nickName {
  182. if (!_nickName) {
  183. _nickName = [[UILabel alloc] initWithFrame:CGRectMake(self.userIcon.right+5, 0, Fitsize(180), 20)];
  184. _nickName.textColor = [UIColor YHColorWithHex:0x333333];
  185. _nickName.font = [UIFont systemFontOfSize:Fitsize(14)];
  186. _nickName.centerY = self.userIcon.centerY;
  187. _nickName.text = self.model.nickname;
  188. }
  189. return _nickName;
  190. }
  191. - (UILabel *)inviteCode {
  192. if (!_inviteCode) {
  193. _inviteCode = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(30), self.userIcon.bottom+FITHeightSIZE(15), FITHeightSIZE(180), 20)];
  194. _inviteCode.textColor = [UIColor YHColorWithHex:0x333333];
  195. _inviteCode.font = [UIFont systemFontOfSize:Fitsize(14)];
  196. _inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",self.model.inviteCode];
  197. }
  198. return _inviteCode;
  199. }
  200. @end