// // YMSimpleMineHeaderView.m // YUMI // // Created by XY on 2023/2/20. // #import "XPSimpleMineHeaderView.h" #import "NetImageView.h" #import #import "DJDKMIMOMColor.h" #import "XPButton.h" /// M #import "UserInfoModel.h" @interface XPSimpleMineHeaderView() /// 背景图 @property (nonatomic, strong) NetImageView *bgImageView; /// 毛玻璃 @property (nonatomic, strong) UIVisualEffectView *effectView; /// 昵称 @property (nonatomic, strong) UILabel *nicknameLabel; /// ID @property (nonatomic, strong) UILabel *idLabel; /// 头像 @property (nonatomic, strong) NetImageView *avatarImageView; /// 关注、粉丝、访客、浏览 @property (nonatomic, strong) UIStackView *numStackView; @property (nonatomic, strong) UIButton *attentionBtn; @property (nonatomic, strong) UIButton *fansBtn; @property (nonatomic, strong) UIButton *visitorBtn; @property (nonatomic, strong) UIButton *browseBtn; /// 钱包、房间、收藏、等级 @property (nonatomic, strong) UIStackView *funcStackView; @property (nonatomic, strong) XPButton *walletBtn; @property (nonatomic, strong) XPButton *roomBtn; @property (nonatomic, strong) XPButton *collectionBtn; @property (nonatomic, strong) XPButton *gradeBtn; @end @implementation XPSimpleMineHeaderView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self createUI]; } return self; } - (void)createUI { [self addSubview:self.bgImageView]; [self.bgImageView addSubview:self.effectView]; [self addSubview:self.nicknameLabel]; [self addSubview:self.idLabel]; [self addSubview:self.avatarImageView]; [self addSubview:self.numStackView]; [self.numStackView addArrangedSubview:self.attentionBtn]; [self.numStackView addArrangedSubview:self.fansBtn]; [self.numStackView addArrangedSubview:self.visitorBtn]; [self.numStackView addArrangedSubview:self.browseBtn]; [self addSubview:self.funcStackView]; [self.funcStackView addArrangedSubview:self.walletBtn]; [self.funcStackView addArrangedSubview:self.roomBtn]; [self.funcStackView addArrangedSubview:self.collectionBtn]; [self.funcStackView addArrangedSubview:self.gradeBtn]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.mas_equalTo(0); make.height.mas_equalTo(260); }]; [self.effectView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.bgImageView); }]; [self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.avatarImageView).offset(-5); make.left.mas_equalTo(16); make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-5); }]; [self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.nicknameLabel.mas_bottom).offset(2); make.left.mas_equalTo(self.nicknameLabel); make.right.mas_equalTo(self.nicknameLabel); }]; [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.bgImageView); make.right.mas_equalTo(-16); make.width.height.mas_equalTo(86); }]; [self.numStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.right.mas_equalTo(-16); make.bottom.mas_equalTo(self.funcStackView.mas_top).offset(-10); make.height.mas_equalTo(30); }]; [self.funcStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.right.mas_equalTo(-16); make.centerY.mas_equalTo(self.bgImageView.mas_bottom); make.height.mas_equalTo(70); }]; } - (void)setUserInfo:(UserInfoModel *)userInfo { _userInfo = userInfo; if (_userInfo) { self.idLabel.text = [NSString stringWithFormat:@"ID:%ld", (long)_userInfo.erbanNo]; self.nicknameLabel.text = _userInfo.nick.length > 0 ? _userInfo.nick : @""; self.avatarImageView.imageUrl = userInfo.avatar; self.bgImageView.imageUrl = userInfo.avatar; NSString *attent = YMLocalizedString(@"XPSimpleMineHeaderView0"); NSString *attentStr = [NSString stringWithFormat:@"%@%ld",attent,_userInfo.followNum]; NSMutableAttributedString *attentAttrStr = [[NSMutableAttributedString alloc] initWithString:attentStr]; [attentAttrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium] range:NSMakeRange(attent.length, attentStr.length-attent.length)]; [self.attentionBtn setAttributedTitle:attentAttrStr forState:UIControlStateNormal]; NSString *fans = YMLocalizedString(@"XPSimpleMineHeaderView1"); NSString *fansStr = [NSString stringWithFormat:@"%@%ld",fans,_userInfo.fansNum]; NSMutableAttributedString *fansAttrStr = [[NSMutableAttributedString alloc] initWithString:fansStr]; [fansAttrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium] range:NSMakeRange(fans.length, fansStr.length-fans.length)]; [self.fansBtn setAttributedTitle:fansAttrStr forState:UIControlStateNormal]; NSString *visitor = YMLocalizedString(@"XPSimpleMineHeaderView2"); NSString *visitorStr = [NSString stringWithFormat:@"%@%ld",visitor,_userInfo.visitNum]; NSMutableAttributedString *visitorAttrStr = [[NSMutableAttributedString alloc] initWithString:visitorStr]; [visitorAttrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium] range:NSMakeRange(visitor.length, visitorStr.length-visitor.length)]; [self.visitorBtn setAttributedTitle:visitorAttrStr forState:UIControlStateNormal]; NSString *browse = YMLocalizedString(@"XPSimpleMineHeaderView3"); NSString *browseStr = [NSString stringWithFormat:@"%@%ld",browse,_userInfo.inRoomNum]; NSMutableAttributedString *browseAttrStr = [[NSMutableAttributedString alloc] initWithString:browseStr]; [browseAttrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium] range:NSMakeRange(browse.length, browseStr.length-browse.length)]; [self.browseBtn setAttributedTitle:browseAttrStr forState:UIControlStateNormal]; } } - (void)btnAction:(UIButton *)button { if (self.delegate && [self.delegate respondsToSelector:@selector(headerViewBtnActionType:)]) { XPMineItemType itemType = -INT_MAX; if (button == self.attentionBtn) { itemType = XPMineItemType_Attention_List; }else if (button == self.fansBtn) { itemType = XPMineItemType_Fans_List; }else if (button == self.visitorBtn) { itemType = XPMineItemType_Visitor; }else if (button == self.browseBtn) { itemType = XPMineItemType_Foot_Print; }else if (button == self.walletBtn) { itemType = XPMineItemType_Account; }else if (button == self.roomBtn) { itemType = XPMineItemType_My_Room; }else if (button == self.collectionBtn) { itemType = XPMineItemType_Collect_Room; }else if (button == self.gradeBtn) { itemType = -1; //我的等级 } [self.delegate headerViewBtnActionType:itemType]; } } /// 点击头像 - (void)tapAvatarImageView { if (self.delegate && [self.delegate respondsToSelector:@selector(headerViewBtnActionType:)]) { [self.delegate headerViewBtnActionType:XPMineItemType_Personinfo]; } } #pragma mark - 懒加载 - (NetImageView *)bgImageView { if (!_bgImageView) { _bgImageView = [[NetImageView alloc] init]; _bgImageView.contentMode = UIViewContentModeScaleAspectFill; _bgImageView.clipsToBounds = YES; } return _bgImageView; } - (UIVisualEffectView *)effectView { if (!_effectView) { UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; _effectView = [[UIVisualEffectView alloc] initWithEffect:blur]; _effectView.alpha = 0.9; } return _effectView; } - (UILabel *)nicknameLabel { if (!_nicknameLabel) { _nicknameLabel = [[UILabel alloc] init]; _nicknameLabel.textColor = UIColor.whiteColor; _nicknameLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightMedium]; } return _nicknameLabel; } - (UILabel *)idLabel { if (!_idLabel) { _idLabel = [[UILabel alloc] init]; _idLabel.textColor = [UIColor.whiteColor colorWithAlphaComponent:0.4]; _idLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular]; } return _idLabel; } - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; config.imageType = ImageTypeUserIcon; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _avatarImageView = [[NetImageView alloc] initWithConfig:config]; _avatarImageView.userInteractionEnabled = YES; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill; _avatarImageView.layer.borderWidth = 2; _avatarImageView.layer.borderColor = [UIColor.whiteColor colorWithAlphaComponent:0.4].CGColor; _avatarImageView.layer.cornerRadius = 86/2; _avatarImageView.clipsToBounds = YES; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAvatarImageView)]; [_avatarImageView addGestureRecognizer:tap]; } return _avatarImageView; } - (UIStackView *)numStackView { if (!_numStackView) { _numStackView = [[UIStackView alloc] init]; _numStackView.axis = UILayoutConstraintAxisHorizontal; _numStackView.distribution = UIStackViewDistributionFillEqually; _numStackView.alignment = UIStackViewAlignmentFill; _numStackView.spacing = 2; } return _numStackView; } - (UIButton *)attentionBtn { if (!_attentionBtn) { _attentionBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_attentionBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _attentionBtn.titleLabel.font = [UIFont systemFontOfSize:10]; _attentionBtn.hidden = YES; [_attentionBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _attentionBtn; } - (UIButton *)fansBtn { if (!_fansBtn) { _fansBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_fansBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _fansBtn.titleLabel.font = [UIFont systemFontOfSize:10]; _fansBtn.hidden = YES; [_fansBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _fansBtn; } - (UIButton *)visitorBtn { if (!_visitorBtn) { _visitorBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_visitorBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _visitorBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [_visitorBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _visitorBtn; } - (UIButton *)browseBtn { if (!_browseBtn) { _browseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_browseBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _browseBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [_browseBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; } return _browseBtn; } - (UIStackView *)funcStackView { if (!_funcStackView) { _funcStackView = [[UIStackView alloc] init]; _funcStackView.axis = UILayoutConstraintAxisHorizontal; _funcStackView.distribution = UIStackViewDistributionFillEqually; _funcStackView.alignment = UIStackViewAlignmentFill; _funcStackView.spacing = 2; _funcStackView.backgroundColor = UIColor.whiteColor; _funcStackView.layer.cornerRadius = 20; _funcStackView.clipsToBounds = YES; } return _funcStackView; } - (XPButton *)walletBtn { if (!_walletBtn) { _walletBtn = [XPButton buttonWithType:UIButtonTypeCustom]; [_walletBtn setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal]; _walletBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [_walletBtn setTitle:YMLocalizedString(@"XPSimpleMineHeaderView4") forState:UIControlStateNormal]; [_walletBtn setImage:[UIImage imageNamed:@"mine_wallet"] forState:UIControlStateNormal]; [_walletBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; _walletBtn.buttonStyle = XPButtonImageTop; _walletBtn.padding = 4; } return _walletBtn; } - (XPButton *)roomBtn { if (!_roomBtn) { _roomBtn = [XPButton buttonWithType:UIButtonTypeCustom]; [_roomBtn setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal]; _roomBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [_roomBtn setTitle:YMLocalizedString(@"XPSimpleMineHeaderView5") forState:UIControlStateNormal]; [_roomBtn setImage:[UIImage imageNamed:@"mine_room"] forState:UIControlStateNormal]; [_roomBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; _roomBtn.buttonStyle = XPButtonImageTop; _roomBtn.padding = 4; } return _roomBtn; } - (XPButton *)collectionBtn { if (!_collectionBtn) { _collectionBtn = [XPButton buttonWithType:UIButtonTypeCustom]; [_collectionBtn setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal]; _collectionBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [_collectionBtn setTitle:YMLocalizedString(@"XPSimpleMineHeaderView6") forState:UIControlStateNormal]; [_collectionBtn setImage:[UIImage imageNamed:@"mine_collection"] forState:UIControlStateNormal]; [_collectionBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; _collectionBtn.buttonStyle = XPButtonImageTop; _collectionBtn.padding = 4; } return _collectionBtn; } - (XPButton *)gradeBtn { if (!_gradeBtn) { _gradeBtn = [XPButton buttonWithType:UIButtonTypeCustom]; [_gradeBtn setTitleColor:[DJDKMIMOMColor mainTextColor] forState:UIControlStateNormal]; _gradeBtn.titleLabel.font = [UIFont systemFontOfSize:10]; [_gradeBtn setTitle:YMLocalizedString(@"XPSimpleMineHeaderView7") forState:UIControlStateNormal]; [_gradeBtn setImage:[UIImage imageNamed:@"mine_grade"] forState:UIControlStateNormal]; [_gradeBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside]; _gradeBtn.buttonStyle = XPButtonImageTop ; _gradeBtn.hidden = YES; _gradeBtn.padding = 4; } return _gradeBtn; } @end