天天省钱快报

KBUserView.m 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // KBUserView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBUserView.h"
  9. @interface KBUserView ()
  10. @property (nonatomic, strong) UIImageView *iconView;
  11. @property (nonatomic, strong) UILabel *nickName;
  12. @end
  13. @implementation KBUserView
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. [self initSubViews];
  18. }
  19. return self;
  20. }
  21. - (void)initSubViews {
  22. self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
  23. self.iconView.layer.borderColor = [UIColor whiteColor].CGColor;
  24. self.iconView.layer.borderWidth = 1;
  25. self.iconView.layer.masksToBounds = YES;
  26. self.iconView.layer.cornerRadius = 30;
  27. self.iconView.userInteractionEnabled = YES;
  28. self.iconView.backgroundColor = [UIColor yhGrayColor];
  29. NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin";
  30. self.iconView.image = [UIImage imageNamed:imgStr];
  31. self.iconView.centerX = self.width/2;
  32. UITapGestureRecognizer *tapIcon = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  33. [self.iconView addGestureRecognizer:tapIcon];
  34. [self addSubview:self.iconView];
  35. self.nickName = [[UILabel alloc] initWithFrame:CGRectMake(30, self.iconView.bottom+10, self.width-60, 25)];
  36. self.nickName.textColor = [UIColor whiteColor];
  37. self.nickName.textAlignment = NSTextAlignmentCenter;
  38. self.nickName.font = [UIFont systemFontOfSize:16];
  39. self.nickName.userInteractionEnabled = YES;
  40. NSString *nameStr = [AccountTool isLogin] ? @"昵称加载中..." : @"点击登录享受更多优惠";
  41. self.nickName.text = nameStr;
  42. UITapGestureRecognizer *tapName = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  43. [self.nickName addGestureRecognizer:tapName];
  44. [self addSubview:self.nickName];
  45. }
  46. - (void)setLoginView:(KBUserInfo *)userInfo {
  47. [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]];
  48. self.nickName.text = userInfo.name;
  49. }
  50. - (void)setUnLoginView {
  51. self.iconView.image = [UIImage imageNamed:@"unlogin"];
  52. self.nickName.text = @"点击登录享受更多优惠";
  53. }
  54. - (void)tapAction {
  55. if (self.tapActionBlock) {
  56. self.tapActionBlock();
  57. }
  58. }
  59. @end