123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- //
- // XYPersonalCenterHeaderView.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2019/12/21.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import "XYPersonalCenterHeaderView.h"
- #import "XYPersonalCenterViewModel.h"
- #import "XYPersonalUserInfoView.h"
- #import "XYPersonalCenterHeaderItemView.h"
- #define itemCount 4
- @interface XYPersonalCenterHeaderView ()
- @property (nonatomic, readwrite, strong) XYPersonalUserInfoView *userInfoView;//90
- //@property (nonatomic, readwrite, strong) XYPersonalUserInfoView *userInfoView;10+74
- /// 会员信息
- @property (nonatomic, readwrite, strong) UIView *vipView;
- @property (nonatomic, readwrite, strong) UIImageView *vipBgImageView;
- @property (nonatomic, readwrite, strong) UIImageView *vipMarkImageView;
- @property (nonatomic, readwrite, strong) UILabel *vipLabel;
- @property (nonatomic, readwrite, strong) UIButton *vipButton;
- @property (nonatomic, readwrite, strong) NSMutableArray *views;
- @end
- @implementation XYPersonalCenterHeaderView
- #pragma mark - Public Method
- - (void)configureViewModel:(XYPersonalCenterViewModel *)viewModel {
-
- [self.userInfoView configureViewWithModel:viewModel.nowUser];
-
- // 会员信息
- self.vipMarkImageView.image = [XYLevelImageHander getVipImageWithLevel:viewModel.nowUser.vipLevel];
- self.vipLabel.text = [XYLevelImageHander getVipNameWithLevel:viewModel.nowUser.vipLevel];
- if ([XYUserInfoManager nowUser].vipLevel > 0 && StringIsNotEmpty([XYAppConfigModel getUrlVip])) {
- self.vipBgImageView.image = ImageNamed(@"icon_vip_bg");
- self.vipView.hidden = NO;
- }else {
- self.vipBgImageView.image = ImageNamed(@"icon_unvip_bg");
- self.vipView.hidden = YES;
- }
-
- for (NSInteger i = 0; i < self.views.count; i++) {
- XYPersonalCenterHeaderItemView *item = self.views[i];
- switch (i) {
- case 0:
- [item setupTitle:kLocalizedString(@"关注") content:[NSString stringWithFormat:@"%ld", (long)viewModel.followCount]];
- break;
- case 1:
- [item setupTitle:kLocalizedString(@"粉丝") content:[NSString stringWithFormat:@"%ld", (long)viewModel.fansCount]];
- break;
- case 2:
- [item setupTitle:kLocalizedString(@"足迹") content:[NSString stringWithFormat:@"%ld", viewModel.visitCount]];
- break;
- case 3:
- [item setupTitle:kLocalizedString(@"访客") content:[NSString stringWithFormat:@"%ld", viewModel.intervieweeCount]];
- item.visitFoot = YES;
- break;
- default:
- break;
- }
- }
- }
- #pragma mark - Private Method
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- // 初始化
- [self _setup];
-
- // 创建子控件
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- #pragma mark - 事件处理Or辅助方法
- - (void)vipButtonAction:(id)sender {
- if (self.delegate && [self.delegate respondsToSelector:@selector(vipAction)]) {
- [self.delegate vipAction];
- }
- }
- #pragma mark - Private Method
- - (void)_setup{
-
- self.views = [NSMutableArray new];
-
- [self addSubview:self.userInfoView];
-
- WeakSelf
- // 登录、查看个人信息
- [self.userInfoView setLoginAction:^{
- if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(loginAction)]) {
- [weakSelf.delegate loginAction];
- }
- }];
- }
- #pragma mark - 创建子控件
- - (void)_setupSubViews{
-
- [self addSubview:self.vipView];
- [self.vipView addSubview:self.vipBgImageView];
- [self.vipView addSubview:self.vipMarkImageView];
- [self.vipView addSubview:self.vipLabel];
- [self.vipView addSubview:self.vipButton];
-
- [self.vipButton addTarget:self action:@selector(vipButtonAction:) forControlEvents:UIControlEventTouchUpInside];
-
- CGFloat width = (self.f_width-30) / itemCount;
- CGFloat y = self.userInfoView.bottom + 10;
-
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, y, self.f_width-30, 74.0f)];
- contentView.backgroundColor = Color_White;
- [self addSubview:contentView];
- kViewRadius(contentView, 16);
-
- for (NSInteger i = 0; i < itemCount; i++) {
- XYPersonalCenterHeaderItemView *item = [[XYPersonalCenterHeaderItemView alloc] initWithFrame:CGRectMake(width * i, 0, width, 74.0f)];
- item.lineView.image = ImageNamed(@"icon_anchor_head_line");
- item.tag = i;
- switch (i) {
- case 0:
- [item setupTitle:kLocalizedString(@"关注") content:@"0"];
- break;
- case 1:
- [item setupTitle:kLocalizedString(@"粉丝") content:@"0"];
- break;
- case 2:
- [item setupTitle:kLocalizedString(@"足迹") content:@"0"];
- break;
- case 3:
- [item setupTitle:kLocalizedString(@"访客") content:@"0"];
- item.lineView.hidden = YES;
- break;
- default:
- break;
- }
- [contentView addSubview:item];
- WeakSelf
- [item setItemClickActionBlock:^(NSInteger index) {
- if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didSelectClickItemWithIndex:)]) {
- [weakSelf.delegate didSelectClickItemWithIndex:index];
- }
- }];
-
- [self.views addObject:item];
- }
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.top.equalTo(self);
- make.width.equalTo(@121.0f);
- make.height.equalTo(@27.0f);
- }];
- [self.vipBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.vipView);
- }];
- [self.vipMarkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.vipView).offset(36.0f);
- make.centerY.equalTo(self.vipView);
- make.width.height.equalTo(@20.0f);
- }];
- [self.vipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.vipMarkImageView.mas_right).offset(3.0f);
- make.centerY.equalTo(self.vipView);
- make.right.equalTo(self.vipView).offset(-10.0f);
- }];
- [self.vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.vipView);
- }];
- }
- - (XYPersonalUserInfoView *)userInfoView {
- if (!_userInfoView) {
- _userInfoView = [[XYPersonalUserInfoView alloc] initWithFrame:CGRectMake(0, 0.0f, self.f_width, 90)];
- [_userInfoView configureViewWithModel:[XYUserInfoManager nowUser]];
- _userInfoView.backgroundColor = [UIColor clearColor];
- }
- return _userInfoView;
- }
- - (UIView *)vipView {
- if (!_vipView) {
- _vipView = [UIView new];
- }
- return _vipView;
- }
- - (UIImageView *)vipBgImageView {
- if (!_vipBgImageView) {
- _vipBgImageView = [UIImageView new];
- _vipBgImageView.image = ImageNamed(@"icon_vip_bg");
- }
- return _vipBgImageView;
- }
- - (UIImageView *)vipMarkImageView {
- if (!_vipMarkImageView) {
- _vipMarkImageView = [UIImageView new];
- }
- return _vipMarkImageView;
- }
- - (UILabel *)vipLabel {
- if (!_vipLabel) {
- _vipLabel = [UILabel createLabelTextColor:Color_White fount:Font_B(12)];
- _vipLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _vipLabel;
- }
- - (UIButton *)vipButton {
- if (!_vipButton) {
- _vipButton = [UIButton buttonWithType:UIButtonTypeCustom];
- }
- return _vipButton;
- }
- @end
|