口袋优选

KBUserView.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. @property (nonatomic, strong) UILabel *tagLb;
  13. @end
  14. @implementation KBUserView
  15. - (instancetype)initWithFrame:(CGRect)frame {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. [self initSubViews];
  19. }
  20. return self;
  21. }
  22. - (void)initSubViews {
  23. self.iconView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 0, 60, 60)];
  24. self.iconView.layer.borderColor = [UIColor whiteColor].CGColor;
  25. self.iconView.layer.borderWidth = 1;
  26. self.iconView.layer.masksToBounds = YES;
  27. self.iconView.layer.cornerRadius = self.iconView.height/2;
  28. self.iconView.userInteractionEnabled = YES;
  29. self.iconView.backgroundColor = [UIColor yhGrayColor];
  30. NSString *imgStr = [AccountTool isLogin] ? @"login" : @"unlogin";
  31. self.iconView.image = [UIImage imageNamed:imgStr];
  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(self.iconView.right+10, self.iconView.top+5, self.width-60, 25)];
  36. self.nickName.textColor = [UIColor whiteColor];
  37. self.nickName.font = [UIFont systemFontOfSize:15];
  38. self.nickName.userInteractionEnabled = YES;
  39. NSString *nameStr = [AccountTool isLogin] ? @"昵称加载中..." : @"点击登录享受更多优惠";
  40. self.nickName.text = nameStr;
  41. UITapGestureRecognizer *tapName = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  42. [self.nickName addGestureRecognizer:tapName];
  43. [self addSubview:self.nickName];
  44. self.tagLb = [[UILabel alloc] initWithFrame:CGRectMake(self.nickName.left, 0, 0, 0)];
  45. self.tagLb.textColor = [UIColor whiteColor];
  46. self.tagLb.textAlignment = NSTextAlignmentCenter;
  47. self.tagLb.font = [UIFont systemFontOfSize:11];
  48. [self addSubview:self.tagLb];
  49. }
  50. - (void)setLoginView:(KBUserInfo *)userInfo {
  51. [self.iconView sd_setImageWithURL:[NSURL URLWithString:userInfo.img] placeholderImage:[UIImage imageNamed:@"login"]];
  52. self.nickName.y = self.iconView.y+3;
  53. self.tagLb.hidden = NO;
  54. self.nickName.text = userInfo.name;
  55. self.tagLb.text = userInfo.tag;
  56. [self.tagLb sizeToFit];
  57. self.tagLb.width += 10;
  58. self.tagLb.height += 4;
  59. self.tagLb.cornerRadius = self.tagLb.height/2;
  60. self.tagLb.backgroundColor = [UIColor colorWithWhite:1 alpha:0.46];
  61. self.tagLb.bottom = self.iconView.bottom-3;
  62. }
  63. - (void)setUnLoginView {
  64. self.iconView.image = [UIImage imageNamed:@"unlogin"];
  65. self.nickName.text = @"点击登录享受更多优惠";
  66. self.tagLb.hidden = YES;
  67. self.nickName.centerY = self.iconView.centerY;
  68. }
  69. - (void)tapAction {
  70. if (self.tapActionBlock) {
  71. self.tapActionBlock();
  72. }
  73. }
  74. @end