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

DRUserInfoView.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // DRUserInfoView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/22.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRUserInfoView.h"
  9. @interface DRUserInfoView()
  10. @property (nonatomic, strong) UIImageView *iconView; //用户头像
  11. @property (nonatomic, strong) UILabel *nickName; //用户昵称
  12. @property (nonatomic, strong) UILabel *unLonginLabel;//未登录文字
  13. @property (nonatomic, strong) UILabel *unLoginDes;//未登录描述
  14. @end
  15. @implementation DRUserInfoView
  16. - (instancetype)initWithFrame:(CGRect)frame {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. [self initSubViews];
  20. }
  21. return self;
  22. }
  23. - (void)initSubViews {
  24. [self addSubview:self.iconView];
  25. [self addSubview:self.nickName];
  26. [self addSubview:self.unLonginLabel];
  27. [self addSubview:self.unLoginDes];
  28. // [self addSubview:self.vipGuideLabel];
  29. ;
  30. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.mas_offset(28);
  32. make.centerY.mas_equalTo(self);
  33. make.width.height.mas_equalTo(60);
  34. }];
  35. [self.unLonginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(14);
  37. make.top.mas_equalTo(self.iconView.mas_top).mas_offset(10);
  38. }];
  39. [self.unLoginDes mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.mas_equalTo(self.unLonginLabel);
  41. make.bottom.mas_equalTo(self.iconView.mas_bottom).mas_offset(-10);
  42. }];
  43. [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.top.mas_equalTo(self.iconView.mas_top).mas_offset(8);
  45. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(14);
  46. make.width.mas_lessThanOrEqualTo(Fitsize(150));
  47. }];
  48. // [self.vipGuideLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. // make.left.mas_equalTo(self.nickName);
  50. // make.width.mas_equalTo(250);
  51. // make.top.mas_equalTo(self.nickName.mas_bottom).mas_offset(10);
  52. // }];
  53. [self setIsLogInView];
  54. }
  55. -(void)clickWithDrawButton {
  56. if (self.clickDraw) {
  57. self.clickDraw();
  58. }
  59. }
  60. - (void)setUserInfo:(DRUserInfo *)userInfo {
  61. _userInfo = userInfo;
  62. [self setIsLogInView];
  63. self.nickName.text = userInfo.name;
  64. [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]];
  65. }
  66. - (void)setIsLogInView {
  67. self.unLonginLabel.hidden = YES;
  68. self.unLoginDes.hidden = YES;
  69. self.nickName.hidden = NO;
  70. self.iconView.image = [UIImage imageNamed:@"login"];
  71. }
  72. - (void)setNologInView {
  73. self.unLonginLabel.hidden = NO;
  74. self.unLoginDes.hidden = NO;
  75. self.nickName.hidden = YES;
  76. self.iconView.image = [UIImage imageNamed:@"unlogin"];
  77. }
  78. #pragma mark ----
  79. /**
  80. 点击登录
  81. */
  82. - (void)goToLoginPage {
  83. if (self.loginClick) {
  84. self.loginClick();
  85. }
  86. }
  87. - (void)settingAction {
  88. if (self.settingClick) {
  89. self.settingClick();
  90. }
  91. }
  92. - (void)tapTypeIcon {
  93. if (self.tapUserType) {
  94. self.tapUserType();
  95. }
  96. }
  97. - (void)copyCodeAction {
  98. UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
  99. if (_userInfo.invite_code) {
  100. pastboard.string = _userInfo.invite_code;
  101. [MBProgressHUD showMessage:@"复制成功"];
  102. }else {
  103. [MBProgressHUD showMessage:@"复制失败"];
  104. }
  105. }
  106. - (void)gotoMyfansAction {
  107. if (self.gotoMyfans) {
  108. self.gotoMyfans();
  109. }
  110. }
  111. - (void)gotoMyIncommeAction {
  112. if (self.gotoMyIncome) {
  113. self.gotoMyIncome();
  114. }
  115. }
  116. #pragma mark ---
  117. - (UIImageView *)iconView {
  118. if (!_iconView) {
  119. _iconView = [[UIImageView alloc] init];
  120. _iconView.layer.cornerRadius = 30;
  121. _iconView.layer.masksToBounds = YES;
  122. NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin";
  123. _iconView.image = [UIImage imageNamed:imgStr];
  124. _iconView.userInteractionEnabled = YES;
  125. _iconView.layer.borderWidth = 2;
  126. _iconView.layer.borderColor = [UIColor whiteColor].CGColor;
  127. UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingAction)];
  128. [_iconView addGestureRecognizer:settingTap];
  129. }
  130. return _iconView;
  131. }
  132. - (UILabel *)nickName {
  133. if (!_nickName) {
  134. _nickName = [[UILabel alloc] init];
  135. _nickName.font = [UIFont systemFontOfSize:16];
  136. _nickName.textColor = [UIColor whiteColor];
  137. _nickName.userInteractionEnabled = YES;
  138. _nickName.text = @"昵称加载中...";
  139. UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingAction)];
  140. [_nickName addGestureRecognizer:settingTap];
  141. }
  142. return _nickName;
  143. }
  144. - (UILabel *)unLonginLabel {
  145. if (!_unLonginLabel) {
  146. _unLonginLabel = [[UILabel alloc] init];
  147. _unLonginLabel.text = @"点击登录";
  148. _unLonginLabel.textColor = [UIColor whiteColor];
  149. _unLonginLabel.font = [UIFont systemFontOfSize:15];
  150. _unLonginLabel.userInteractionEnabled = YES;
  151. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToLoginPage)];
  152. [_unLonginLabel addGestureRecognizer:tap];
  153. }
  154. return _unLonginLabel;
  155. }
  156. - (UILabel *)unLoginDes {
  157. if (!_unLoginDes) {
  158. _unLoginDes = [[UILabel alloc] init];
  159. _unLoginDes.text = @"登录后可以领取更多优惠券哦";
  160. _unLoginDes.textColor = [UIColor whiteColor];
  161. _unLoginDes.font = [UIFont systemFontOfSize:13];
  162. _unLoginDes.userInteractionEnabled = YES;
  163. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToLoginPage)];
  164. [_unLoginDes addGestureRecognizer:tap];
  165. }
  166. return _unLoginDes;
  167. }
  168. @end