口袋优选

KBUserInfoView.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. //
  2. // KBUserInfoView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/22.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBUserInfoView.h"
  9. @interface KBUserInfoView()
  10. @property (nonatomic, strong) UIImageView *iconView; //用户头像
  11. @property (nonatomic, strong) UILabel *nickName; //用户昵称
  12. @property (nonatomic, strong) UILabel *inviteCode; //邀请码
  13. @property (nonatomic, strong) UIImageView *userTypeIcon; //用户类型图标
  14. @property (nonatomic, strong) UIButton *inviteCopyBtn;//复制按钮
  15. @property (nonatomic, strong) UILabel *unLonginLabel;//未登录文字
  16. @property (nonatomic, strong) UILabel *unLoginDes;//未登录描述
  17. @property (nonatomic, strong) UILabel *vipGuideLabel;
  18. @end
  19. @implementation KBUserInfoView
  20. - (instancetype)initWithFrame:(CGRect)frame {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. [self initSubViews];
  24. }
  25. return self;
  26. }
  27. - (void)initSubViews {
  28. [self addSubview:self.iconView];
  29. [self addSubview:self.nickName];
  30. [self addSubview:self.userTypeIcon];
  31. [self addSubview:self.inviteCode];
  32. [self addSubview:self.inviteCopyBtn];
  33. [self addSubview:self.unLonginLabel];
  34. [self addSubview:self.unLoginDes];
  35. [self addSubview:self.vipGuideLabel];
  36. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_offset(28);
  38. make.centerY.mas_equalTo(self);
  39. make.width.height.mas_equalTo(60);
  40. }];
  41. [self.unLonginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(14);
  43. make.top.mas_equalTo(self.iconView.mas_top).mas_offset(10);
  44. }];
  45. [self.unLoginDes mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(self.unLonginLabel);
  47. make.bottom.mas_equalTo(self.iconView.mas_bottom).mas_offset(-10);
  48. }];
  49. [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.mas_equalTo(self.iconView.mas_top).mas_offset(8);
  51. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(14);
  52. }];
  53. [self.inviteCode mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.mas_equalTo(self.nickName);
  55. make.top.mas_equalTo(self.nickName.mas_bottom).mas_offset(10);
  56. }];
  57. [self.vipGuideLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(self.nickName);
  59. make.width.mas_equalTo(250);
  60. make.top.mas_equalTo(self.nickName.mas_bottom).mas_offset(10);
  61. }];
  62. [self.userTypeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.mas_equalTo(self.nickName.mas_right).mas_offset(10);
  64. make.centerY.mas_equalTo(self.nickName);
  65. make.width.height.mas_equalTo(20);
  66. }];
  67. [self.inviteCopyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(self.inviteCode.mas_right).mas_offset(10);
  69. make.centerY.mas_equalTo(self.inviteCode);
  70. make.width.mas_equalTo(34);
  71. make.height.mas_equalTo(14);
  72. }];
  73. self.inviteCode.hidden = YES;
  74. self.inviteCopyBtn.hidden = YES;
  75. self.vipGuideLabel.hidden = YES;
  76. [self setIsLogInView];
  77. }
  78. - (void)setUserInfo:(KBUserInfo *)userInfo {
  79. _userInfo = userInfo;
  80. [self setIsLogInView];
  81. self.nickName.text = userInfo.name;
  82. if (userInfo.name.length > 10) {
  83. [self.nickName mas_updateConstraints:^(MASConstraintMaker *make) {
  84. make.width.mas_equalTo(150);
  85. }];
  86. }
  87. self.inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",userInfo.invite_code];
  88. NSString *imgStr;
  89. switch ([userInfo.user_level integerValue]) {
  90. case 1:
  91. {
  92. imgStr = @"vip_icon";
  93. }
  94. break;
  95. case 2:
  96. {
  97. imgStr = @"svip_icon";
  98. }
  99. break;
  100. case 3:
  101. {
  102. imgStr = @"operator_icon";
  103. }
  104. break;
  105. default:
  106. break;
  107. }
  108. UIImage *image = [UIImage imageNamed:imgStr];
  109. self.userTypeIcon.image = image;
  110. [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]];
  111. [self.userTypeIcon mas_updateConstraints:^(MASConstraintMaker *make) {
  112. make.width.mas_equalTo(image.size.width);
  113. make.height.mas_equalTo(image.size.height);
  114. }];
  115. BOOL showVipGuideLabel = [userInfo.user_level isEqualToString:@"1"];
  116. self.vipGuideLabel.hidden = !showVipGuideLabel;
  117. self.inviteCode.hidden = showVipGuideLabel;
  118. self.inviteCopyBtn.hidden = showVipGuideLabel;
  119. }
  120. - (void)setIsLogInView {
  121. self.vipGuideLabel.hidden = YES;
  122. BOOL isLogin = [AccountTool isLogin];
  123. self.unLonginLabel.hidden = isLogin;
  124. self.unLoginDes.hidden = isLogin;
  125. self.nickName.hidden = !isLogin;
  126. self.userTypeIcon.hidden = !isLogin;
  127. // self.vipGuideLabel.hidden = !isLogin;
  128. self.inviteCode.hidden = !isLogin;
  129. self.inviteCopyBtn.hidden = !isLogin;
  130. if (!isLogin) self.iconView.image = [UIImage imageNamed:@"unlogin"];
  131. }
  132. #pragma mark ----
  133. /**
  134. 点击登录
  135. */
  136. - (void)goToLoginPage {
  137. if (self.loginClick) {
  138. self.loginClick();
  139. }
  140. }
  141. - (void)settingAction {
  142. if (self.settingClick) {
  143. self.settingClick();
  144. }
  145. }
  146. - (void)tapTypeIcon {
  147. if (self.tapUserType) {
  148. self.tapUserType();
  149. }
  150. }
  151. - (void)copyCodeAction {
  152. UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
  153. if (_userInfo.invite_code) {
  154. pastboard.string = _userInfo.invite_code;
  155. [MBProgressHUD showMessage:@"复制成功"];
  156. }else {
  157. [MBProgressHUD showMessage:@"复制失败"];
  158. }
  159. }
  160. - (UIImageView *)iconView {
  161. if (!_iconView) {
  162. _iconView = [[UIImageView alloc] init];
  163. _iconView.layer.cornerRadius = 30;
  164. _iconView.layer.masksToBounds = YES;
  165. NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin";
  166. _iconView.image = [UIImage imageNamed:imgStr];
  167. _iconView.userInteractionEnabled = YES;
  168. _iconView.layer.borderWidth = 2;
  169. _iconView.layer.borderColor = [UIColor whiteColor].CGColor;
  170. UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingAction)];
  171. [_iconView addGestureRecognizer:settingTap];
  172. }
  173. return _iconView;
  174. }
  175. - (UILabel *)nickName {
  176. if (!_nickName) {
  177. _nickName = [[UILabel alloc] init];
  178. _nickName.font = [UIFont systemFontOfSize:16];
  179. _nickName.textColor = [UIColor whiteColor];
  180. _nickName.userInteractionEnabled = YES;
  181. _nickName.text = @"省钱小达人";
  182. UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingAction)];
  183. [_nickName addGestureRecognizer:settingTap];
  184. }
  185. return _nickName;
  186. }
  187. - (UIImageView *)userTypeIcon {
  188. if (!_userTypeIcon) {
  189. _userTypeIcon = [[UIImageView alloc] init];
  190. _userTypeIcon.userInteractionEnabled = YES;
  191. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTypeIcon)];
  192. [_userTypeIcon addGestureRecognizer:tap];
  193. }
  194. return _userTypeIcon;
  195. }
  196. - (UILabel *)inviteCode {
  197. if (!_inviteCode) {
  198. _inviteCode = [[UILabel alloc] init];
  199. _inviteCode.font = [UIFont systemFontOfSize:14];
  200. _inviteCode.textColor = [UIColor whiteColor];
  201. _inviteCode.text = @"邀请码:";
  202. }
  203. return _inviteCode;
  204. }
  205. - (UIButton *)inviteCopyBtn {
  206. if (!_inviteCopyBtn) {
  207. _inviteCopyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  208. _inviteCopyBtn.layer.cornerRadius = 7;
  209. _inviteCopyBtn.layer.borderColor = [UIColor whiteColor].CGColor;
  210. _inviteCopyBtn.layer.borderWidth = 1;
  211. _inviteCopyBtn.titleLabel.font = [UIFont systemFontOfSize:11];
  212. [_inviteCopyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  213. [_inviteCopyBtn setTitle:@"复制" forState:UIControlStateNormal];
  214. [_inviteCopyBtn addTarget:self action:@selector(copyCodeAction) forControlEvents:UIControlEventTouchUpInside];
  215. }
  216. return _inviteCopyBtn;
  217. }
  218. - (UILabel *)unLonginLabel {
  219. if (!_unLonginLabel) {
  220. _unLonginLabel = [[UILabel alloc] init];
  221. _unLonginLabel.text = @"点击登录";
  222. _unLonginLabel.textColor = [UIColor whiteColor];
  223. _unLonginLabel.font = [UIFont systemFontOfSize:15];
  224. _unLonginLabel.userInteractionEnabled = YES;
  225. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToLoginPage)];
  226. [_unLonginLabel addGestureRecognizer:tap];
  227. }
  228. return _unLonginLabel;
  229. }
  230. - (UILabel *)unLoginDes {
  231. if (!_unLoginDes) {
  232. _unLoginDes = [[UILabel alloc] init];
  233. _unLoginDes.text = @"登录后可以领取优惠券哦";
  234. _unLoginDes.textColor = [UIColor whiteColor];
  235. _unLoginDes.font = [UIFont systemFontOfSize:13];
  236. _unLoginDes.userInteractionEnabled = YES;
  237. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToLoginPage)];
  238. [_unLoginDes addGestureRecognizer:tap];
  239. }
  240. return _unLoginDes;
  241. }
  242. - (UILabel *)vipGuideLabel {
  243. if (!_vipGuideLabel) {
  244. _vipGuideLabel = [[UILabel alloc] init];
  245. NSString *text = @"成为超级会员购物领佣金";
  246. _vipGuideLabel.text = text;
  247. _vipGuideLabel.textColor = [UIColor whiteColor];
  248. _vipGuideLabel.font = [UIFont systemFontOfSize:13];
  249. _vipGuideLabel.userInteractionEnabled = YES;
  250. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTypeIcon)];
  251. [_vipGuideLabel addGestureRecognizer:tap];
  252. UIButton *right = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 34, 14)];
  253. right.layer.cornerRadius = 7;
  254. right.layer.borderColor = [UIColor whiteColor].CGColor;
  255. right.layer.borderWidth = 1;
  256. right.titleLabel.font = [UIFont systemFontOfSize:11];
  257. [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  258. [right setTitle:@"升级" forState:UIControlStateNormal];
  259. CGSize size = [PublicFunction getAutoWidthWith:text andSize:CGSizeMake(MAXFLOAT, 20) andFont:13];
  260. right.left = size.width+5;
  261. right.centerY = 8;
  262. [right addTarget:self action:@selector(tapTypeIcon) forControlEvents:UIControlEventTouchUpInside];
  263. [_vipGuideLabel addSubview:right];
  264. _vipGuideLabel.hidden = YES;
  265. }
  266. return _vipGuideLabel;
  267. }
  268. @end