// // KBUserView.m // YouHuiProject // // Created by 小花 on 2018/7/24. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBUserView.h" @interface KBUserView () @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UILabel *nickName; @property (nonatomic, strong) UILabel *tagLb; @end @implementation KBUserView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } - (void)initSubViews { self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 0, 60, 60)]; self.iconView.layer.borderColor = [UIColor whiteColor].CGColor; self.iconView.layer.borderWidth = 1; self.iconView.layer.masksToBounds = YES; self.iconView.layer.cornerRadius = self.iconView.height/2; self.iconView.userInteractionEnabled = YES; self.iconView.backgroundColor = [UIColor yhGrayColor]; NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin"; self.iconView.image = [UIImage imageNamed:imgStr]; UITapGestureRecognizer *tapIcon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; [self.iconView addGestureRecognizer:tapIcon]; [self addSubview:self.iconView]; self.nickName = [[UILabel alloc] initWithFrame:CGRectMake(self.iconView.right+10, self.iconView.top+5, self.width-60, 25)]; self.nickName.textColor = [UIColor whiteColor]; self.nickName.font = [UIFont systemFontOfSize:15]; self.nickName.userInteractionEnabled = YES; NSString *nameStr = [AccountTool isLogin] ? @"昵称加载中..." : @"点击登录享受更多优惠"; self.nickName.text = nameStr; UITapGestureRecognizer *tapName = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; [self.nickName addGestureRecognizer:tapName]; [self addSubview:self.nickName]; self.tagLb = [[UILabel alloc] initWithFrame:CGRectMake(self.nickName.left, 0, 0, 0)]; self.tagLb.textColor = [UIColor whiteColor]; self.tagLb.textAlignment = NSTextAlignmentCenter; self.tagLb.font = [UIFont systemFontOfSize:11]; [self addSubview:self.tagLb]; } - (void)setLoginView:(KBUserInfo *)userInfo { [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]]; self.nickName.y = self.iconView.y+3; self.tagLb.hidden = NO; self.nickName.text = userInfo.name; self.tagLb.text = userInfo.tag; [self.tagLb sizeToFit]; self.tagLb.width += 10; self.tagLb.height += 4; self.tagLb.cornerRadius = self.tagLb.height/2; self.tagLb.backgroundColor = [UIColor colorWithWhite:1 alpha:0.46]; self.tagLb.bottom = self.iconView.bottom-3; } - (void)setUnLoginView { self.iconView.image = [UIImage imageNamed:@"unlogin"]; self.nickName.text = @"点击登录享受更多优惠"; self.tagLb.hidden = YES; self.nickName.centerY = self.iconView.centerY; } - (void)tapAction { if (self.tapActionBlock) { self.tapActionBlock(); } } @end