207 lines
5.7 KiB
Mathematica
207 lines
5.7 KiB
Mathematica
![]() |
//
|
||
|
// XPMineHeadView.m
|
||
|
// xplan-ios
|
||
|
//
|
||
|
// Created by 冯硕 on 2021/9/16.
|
||
|
//
|
||
|
|
||
|
#import "XPMineHeadView.h"
|
||
|
///Third
|
||
|
#import <Masonry/Masonry.h>
|
||
|
#import <YYText/YYLabel.h>
|
||
|
///Tool
|
||
|
#import "ThemeColor.h"
|
||
|
#import "XPMacro.h"
|
||
|
///View
|
||
|
#import "XPMineAccountView.h"
|
||
|
///Model
|
||
|
#import "UserInfoModel.h"
|
||
|
|
||
|
@interface XPMineHeadView ()
|
||
|
///头像
|
||
|
@property (nonatomic,strong) UIImageView * avatarImageView;
|
||
|
///name的容器
|
||
|
@property (nonatomic,strong) UIStackView *nameStackView;
|
||
|
///名字
|
||
|
@property (nonatomic,strong) UILabel *nameLabel;
|
||
|
///编辑
|
||
|
@property (nonatomic,strong) UIButton *editButton;
|
||
|
///id 的容器
|
||
|
@property (nonatomic,strong) UIStackView *idStackView;
|
||
|
///id
|
||
|
@property (nonatomic,strong) UILabel *idLabel;
|
||
|
///性别
|
||
|
@property (nonatomic,strong) UIImageView *sexImageView;
|
||
|
///显示等级
|
||
|
@property (nonatomic,strong) YYLabel *levelLabel;
|
||
|
///我的账户 推荐给好友
|
||
|
@property (nonatomic,strong) XPMineAccountView *accountView;
|
||
|
@end
|
||
|
|
||
|
@implementation XPMineHeadView
|
||
|
|
||
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
{
|
||
|
self = [super initWithFrame:frame];
|
||
|
if (self) {
|
||
|
[self initSubViews];
|
||
|
[self initSubViewConstraints];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
#pragma mark - Response
|
||
|
- (void)tapAvatarImageView {
|
||
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineHeadView:didClickAvatar:)]) {
|
||
|
[self.delegate xPMineHeadView:self didClickAvatar:self.userInfo];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#pragma mark - Private Method
|
||
|
- (void)initSubViews {
|
||
|
self.backgroundColor = [UIColor clearColor];
|
||
|
[self addSubview:self.avatarImageView];
|
||
|
[self addSubview:self.nameStackView];
|
||
|
[self addSubview:self.idStackView];
|
||
|
[self addSubview:self.levelLabel];
|
||
|
[self addSubview:self.accountView];
|
||
|
|
||
|
[self.nameStackView addArrangedSubview:self.nameLabel];
|
||
|
[self.nameStackView addArrangedSubview:self.editButton];
|
||
|
[self.idStackView addArrangedSubview:self.idLabel];
|
||
|
[self.idStackView addArrangedSubview:self.sexImageView];
|
||
|
|
||
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAvatarImageView)];
|
||
|
[self.avatarImageView addGestureRecognizer:tap];
|
||
|
}
|
||
|
|
||
|
- (void)initSubViewConstraints {
|
||
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.size.mas_equalTo(CGSizeMake(50, 50));
|
||
|
make.left.mas_equalTo(self).offset(20);
|
||
|
make.top.mas_equalTo(self).offset(50 + kSafeAreaTopHeight);
|
||
|
}];
|
||
|
|
||
|
[self.nameStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(17);
|
||
|
make.top.mas_equalTo(self.avatarImageView).offset(8);
|
||
|
}];
|
||
|
|
||
|
[self.idStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.nameStackView);
|
||
|
make.top.mas_equalTo(self.nameStackView.mas_bottom).offset(6);
|
||
|
}];
|
||
|
|
||
|
[self.levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.nameStackView);
|
||
|
make.top.mas_equalTo(self.idStackView.mas_bottom).offset(4);
|
||
|
}];
|
||
|
|
||
|
[self.accountView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.right.mas_equalTo(self);
|
||
|
make.height.mas_equalTo(60);
|
||
|
make.top.mas_equalTo(self.levelLabel.mas_bottom).offset(16);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
#pragma mark - Getters And Setters
|
||
|
- (void)setUserInfo:(UserInfoModel *)userInfo {
|
||
|
_userInfo = userInfo;
|
||
|
if (_userInfo) {
|
||
|
self.idLabel.text = [NSString stringWithFormat:@"音游号:%ld", (long)_userInfo.erbanNo];
|
||
|
self.nameLabel.text = _userInfo.nick.length > 0 ? _userInfo.nick : @"";
|
||
|
NSString * sexName;
|
||
|
if (userInfo.gender == GenderType_Male) {
|
||
|
sexName = @"";
|
||
|
} else {
|
||
|
sexName = @"";
|
||
|
}
|
||
|
self.sexImageView.image = [UIImage imageNamed:sexName];
|
||
|
}
|
||
|
}
|
||
|
- (UIImageView *)avatarImageView {
|
||
|
if (!_avatarImageView) {
|
||
|
_avatarImageView = [[UIImageView alloc] init];
|
||
|
_avatarImageView.userInteractionEnabled = YES;
|
||
|
_avatarImageView.layer.masksToBounds = YES;
|
||
|
_avatarImageView.layer.cornerRadius = 25;
|
||
|
}
|
||
|
return _avatarImageView;
|
||
|
}
|
||
|
|
||
|
- (UIStackView *)nameStackView {
|
||
|
if (!_nameStackView) {
|
||
|
_nameStackView = [[UIStackView alloc] init];
|
||
|
_nameStackView.axis = UILayoutConstraintAxisHorizontal;
|
||
|
_nameStackView.distribution = UIStackViewDistributionFill;
|
||
|
_nameStackView.alignment = UIStackViewAlignmentCenter;
|
||
|
_nameStackView.spacing = 5;
|
||
|
}
|
||
|
return _nameStackView;
|
||
|
}
|
||
|
|
||
|
- (UILabel *)nameLabel {
|
||
|
if (!_nameLabel) {
|
||
|
_nameLabel = [[UILabel alloc] init];
|
||
|
_nameLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
|
||
|
_nameLabel.textColor = [ThemeColor mainTextColor];
|
||
|
}
|
||
|
return _nameLabel;
|
||
|
}
|
||
|
|
||
|
- (UIButton *)editButton {
|
||
|
if (!_editButton) {
|
||
|
_editButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
[_editButton setImage:[UIImage imageNamed:@"mine_head_name_edit"] forState:UIControlStateNormal];
|
||
|
[_editButton setImage:[UIImage imageNamed:@"mine_head_name_edit"] forState:UIControlStateSelected];
|
||
|
}
|
||
|
return _editButton;
|
||
|
}
|
||
|
|
||
|
|
||
|
- (UIStackView *)idStackView {
|
||
|
if (!_idStackView) {
|
||
|
_idStackView = [[UIStackView alloc] init];
|
||
|
_idStackView.axis = UILayoutConstraintAxisHorizontal;
|
||
|
_idStackView.distribution = UIStackViewDistributionFill;
|
||
|
_idStackView.alignment = UIStackViewAlignmentCenter;
|
||
|
_idStackView.spacing = 5;
|
||
|
}
|
||
|
return _idStackView;
|
||
|
}
|
||
|
|
||
|
- (UILabel *)idLabel {
|
||
|
if (!_idLabel) {
|
||
|
_idLabel = [[UILabel alloc] init];
|
||
|
_idLabel.font = [UIFont systemFontOfSize:13];
|
||
|
_idLabel.textColor = [ThemeColor secondTextColor];
|
||
|
}
|
||
|
return _idLabel;
|
||
|
}
|
||
|
|
||
|
- (UIImageView *)sexImageView {
|
||
|
if (!_sexImageView) {
|
||
|
_sexImageView = [[UIImageView alloc] init];
|
||
|
_sexImageView.userInteractionEnabled = YES;
|
||
|
}
|
||
|
return _sexImageView;
|
||
|
}
|
||
|
|
||
|
- (YYLabel *)levelLabel {
|
||
|
if (!_levelLabel) {
|
||
|
_levelLabel = [[YYLabel alloc] init];
|
||
|
_levelLabel.preferredMaxLayoutWidth = KScreenWidth - 88;
|
||
|
}
|
||
|
return _levelLabel;
|
||
|
}
|
||
|
|
||
|
- (XPMineAccountView *)accountView {
|
||
|
if (!_accountView) {
|
||
|
_accountView = [[XPMineAccountView alloc] init];
|
||
|
}
|
||
|
return _accountView;
|
||
|
}
|
||
|
|
||
|
|
||
|
@end
|