// // 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; @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(0, 0, 60, 60)]; self.iconView.layer.borderColor = [UIColor whiteColor].CGColor; self.iconView.layer.borderWidth = 1; self.iconView.layer.masksToBounds = YES; self.iconView.layer.cornerRadius = 30; self.iconView.userInteractionEnabled = YES; self.iconView.backgroundColor = [UIColor yhGrayColor]; NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin"; self.iconView.image = [UIImage imageNamed:imgStr]; self.iconView.centerX = self.width/2; UITapGestureRecognizer *tapIcon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; [self.iconView addGestureRecognizer:tapIcon]; [self addSubview:self.iconView]; self.nickName = [[UILabel alloc] initWithFrame:CGRectMake(30, self.iconView.bottom+10, self.width-60, 25)]; self.nickName.textColor = [UIColor whiteColor]; self.nickName.textAlignment = NSTextAlignmentCenter; self.nickName.font = [UIFont systemFontOfSize:16]; 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]; } - (void)setLoginView:(KBUserInfo *)userInfo { [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]]; self.nickName.text = userInfo.name; } - (void)setUnLoginView { self.iconView.image = [UIImage imageNamed:@"unlogin"]; self.nickName.text = @"点击登录享受更多优惠"; } - (void)tapAction { if (self.tapActionBlock) { self.tapActionBlock(); } } @end