123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- //
- // KBUserInfoView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/22.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBUserInfoView.h"
- @interface KBUserInfoView()
- @property (nonatomic, strong) UIImageView *iconView; //用户头像
- @property (nonatomic, strong) UILabel *nickName; //用户昵称
- @property (nonatomic, strong) UILabel *inviteCode; //邀请码
- @property (nonatomic, strong) UIImageView *userTypeIcon; //用户类型图标
- @property (nonatomic, strong) UIButton *inviteCopyBtn;//复制按钮
- @property (nonatomic, strong) UILabel *unLonginLabel;//未登录文字
- @property (nonatomic, strong) UILabel *unLoginDes;//未登录描述
- @property (nonatomic, strong) UILabel *vipGuideLabel;
- @end
- @implementation KBUserInfoView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initSubViews];
- }
- return self;
- }
- - (void)initSubViews {
-
- [self addSubview:self.iconView];
- [self addSubview:self.nickName];
- [self addSubview:self.userTypeIcon];
- [self addSubview:self.inviteCode];
- [self addSubview:self.inviteCopyBtn];
- [self addSubview:self.unLonginLabel];
- [self addSubview:self.unLoginDes];
- [self addSubview:self.vipGuideLabel];
-
- [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(28);
- make.centerY.mas_equalTo(self);
- make.width.height.mas_equalTo(60);
- }];
-
- [self.unLonginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.iconView.mas_right).mas_offset(14);
- make.top.mas_equalTo(self.iconView.mas_top).mas_offset(10);
- }];
-
- [self.unLoginDes mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.unLonginLabel);
- make.bottom.mas_equalTo(self.iconView.mas_bottom).mas_offset(-10);
- }];
-
- [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.iconView.mas_top).mas_offset(8);
- make.left.mas_equalTo(self.iconView.mas_right).mas_offset(14);
- }];
-
- [self.inviteCode mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.nickName);
- make.top.mas_equalTo(self.nickName.mas_bottom).mas_offset(10);
- }];
-
- [self.vipGuideLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.nickName);
- make.width.mas_equalTo(250);
- make.top.mas_equalTo(self.nickName.mas_bottom).mas_offset(10);
- }];
-
- [self.userTypeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.nickName.mas_right).mas_offset(10);
- make.centerY.mas_equalTo(self.nickName);
- make.width.height.mas_equalTo(20);
- }];
-
- [self.inviteCopyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.inviteCode.mas_right).mas_offset(10);
- make.centerY.mas_equalTo(self.inviteCode);
- make.width.mas_equalTo(34);
- make.height.mas_equalTo(14);
- }];
-
-
- self.inviteCode.hidden = YES;
- self.inviteCopyBtn.hidden = YES;
- self.vipGuideLabel.hidden = YES;
-
- [self setIsLogInView];
-
-
- }
- - (void)setUserInfo:(KBUserInfo *)userInfo {
- _userInfo = userInfo;
- [self setIsLogInView];
-
- self.nickName.text = userInfo.name;
- if (userInfo.name.length > 10) {
- [self.nickName mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(150);
- }];
- }
- self.inviteCode.text = [NSString stringWithFormat:@"邀请码:%@",userInfo.invite_code];
-
- NSString *imgStr;
- switch ([userInfo.user_level integerValue]) {
- case 1:
- {
- imgStr = @"vip_icon";
- }
- break;
- case 2:
- {
- imgStr = @"svip_icon";
- }
- break;
- case 3:
- {
- imgStr = @"operator_icon";
- }
- break;
-
- default:
- break;
- }
- UIImage *image = [UIImage imageNamed:imgStr];
- self.userTypeIcon.image = image;
- [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]];
- [self.userTypeIcon mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(image.size.width);
- make.height.mas_equalTo(image.size.height);
- }];
-
- BOOL showVipGuideLabel = [userInfo.user_level isEqualToString:@"1"];
- self.vipGuideLabel.hidden = !showVipGuideLabel;
- self.inviteCode.hidden = showVipGuideLabel;
- self.inviteCopyBtn.hidden = showVipGuideLabel;
-
-
-
- }
- - (void)setIsLogInView {
- self.vipGuideLabel.hidden = YES;
- BOOL isLogin = [AccountTool isLogin];
- self.unLonginLabel.hidden = isLogin;
- self.unLoginDes.hidden = isLogin;
- self.nickName.hidden = !isLogin;
- self.userTypeIcon.hidden = !isLogin;
- // self.vipGuideLabel.hidden = !isLogin;
- self.inviteCode.hidden = !isLogin;
- self.inviteCopyBtn.hidden = !isLogin;
-
- if (!isLogin) self.iconView.image = [UIImage imageNamed:@"unlogin"];
- }
- #pragma mark ----
- /**
- 点击登录
- */
- - (void)goToLoginPage {
- if (self.loginClick) {
- self.loginClick();
- }
- }
- - (void)settingAction {
- if (self.settingClick) {
- self.settingClick();
- }
- }
- - (void)tapTypeIcon {
- if (self.tapUserType) {
- self.tapUserType();
- }
- }
- - (void)copyCodeAction {
- UIPasteboard * pastboard = [UIPasteboard generalPasteboard];
- if (_userInfo.invite_code) {
- pastboard.string = _userInfo.invite_code;
- [MBProgressHUD showMessage:@"复制成功"];
- }else {
- [MBProgressHUD showMessage:@"复制失败"];
- }
-
- }
- - (UIImageView *)iconView {
- if (!_iconView) {
- _iconView = [[UIImageView alloc] init];
- _iconView.layer.cornerRadius = 30;
- _iconView.layer.masksToBounds = YES;
- NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin";
- _iconView.image = [UIImage imageNamed:imgStr];
- _iconView.userInteractionEnabled = YES;
- _iconView.layer.borderWidth = 2;
- _iconView.layer.borderColor = [UIColor whiteColor].CGColor;
- UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingAction)];
- [_iconView addGestureRecognizer:settingTap];
- }
- return _iconView;
- }
- - (UILabel *)nickName {
- if (!_nickName) {
- _nickName = [[UILabel alloc] init];
- _nickName.font = [UIFont systemFontOfSize:16];
- _nickName.textColor = [UIColor whiteColor];
- _nickName.userInteractionEnabled = YES;
- _nickName.text = @"省钱小达人";
- UITapGestureRecognizer *settingTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingAction)];
- [_nickName addGestureRecognizer:settingTap];
- }
- return _nickName;
- }
- - (UIImageView *)userTypeIcon {
- if (!_userTypeIcon) {
- _userTypeIcon = [[UIImageView alloc] init];
- _userTypeIcon.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTypeIcon)];
- [_userTypeIcon addGestureRecognizer:tap];
- }
- return _userTypeIcon;
- }
- - (UILabel *)inviteCode {
- if (!_inviteCode) {
- _inviteCode = [[UILabel alloc] init];
- _inviteCode.font = [UIFont systemFontOfSize:14];
- _inviteCode.textColor = [UIColor whiteColor];
- _inviteCode.text = @"邀请码:";
- }
- return _inviteCode;
- }
- - (UIButton *)inviteCopyBtn {
- if (!_inviteCopyBtn) {
- _inviteCopyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _inviteCopyBtn.layer.cornerRadius = 7;
- _inviteCopyBtn.layer.borderColor = [UIColor whiteColor].CGColor;
- _inviteCopyBtn.layer.borderWidth = 1;
- _inviteCopyBtn.titleLabel.font = [UIFont systemFontOfSize:11];
- [_inviteCopyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [_inviteCopyBtn setTitle:@"复制" forState:UIControlStateNormal];
- [_inviteCopyBtn addTarget:self action:@selector(copyCodeAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _inviteCopyBtn;
- }
- - (UILabel *)unLonginLabel {
- if (!_unLonginLabel) {
- _unLonginLabel = [[UILabel alloc] init];
- _unLonginLabel.text = @"点击登录";
- _unLonginLabel.textColor = [UIColor whiteColor];
- _unLonginLabel.font = [UIFont systemFontOfSize:15];
- _unLonginLabel.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToLoginPage)];
- [_unLonginLabel addGestureRecognizer:tap];
- }
- return _unLonginLabel;
- }
- - (UILabel *)unLoginDes {
- if (!_unLoginDes) {
- _unLoginDes = [[UILabel alloc] init];
- _unLoginDes.text = @"登录后可以领取优惠券哦";
- _unLoginDes.textColor = [UIColor whiteColor];
- _unLoginDes.font = [UIFont systemFontOfSize:13];
- _unLoginDes.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToLoginPage)];
- [_unLoginDes addGestureRecognizer:tap];
- }
- return _unLoginDes;
- }
- - (UILabel *)vipGuideLabel {
- if (!_vipGuideLabel) {
- _vipGuideLabel = [[UILabel alloc] init];
- NSString *text = @"成为超级会员购物领佣金";
- _vipGuideLabel.text = text;
- _vipGuideLabel.textColor = [UIColor whiteColor];
- _vipGuideLabel.font = [UIFont systemFontOfSize:13];
- _vipGuideLabel.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTypeIcon)];
- [_vipGuideLabel addGestureRecognizer:tap];
-
- UIButton *right = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 34, 14)];
- right.layer.cornerRadius = 7;
- right.layer.borderColor = [UIColor whiteColor].CGColor;
- right.layer.borderWidth = 1;
- right.titleLabel.font = [UIFont systemFontOfSize:11];
- [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [right setTitle:@"升级" forState:UIControlStateNormal];
- CGSize size = [PublicFunction getAutoWidthWith:text andSize:CGSizeMake(MAXFLOAT, 20) andFont:13];
- right.left = size.width+5;
- right.centerY = 8;
- [right addTarget:self action:@selector(tapTypeIcon) forControlEvents:UIControlEventTouchUpInside];
- [_vipGuideLabel addSubview:right];
-
- _vipGuideLabel.hidden = YES;
- }
- return _vipGuideLabel;
- }
- @end
|