Files
my_yuyin/QXLive/Mine(音域)/View/QXMainHeaderView.m

243 lines
11 KiB
Mathematica
Raw Normal View History

2025-09-22 18:48:29 +08:00
//
// QXMainHeaderView.m
// QXLive
//
// Created by on 2025/5/9.
//
#import "QXMainHeaderView.h"
#import "QXSeatHeaderView.h"
#import "CKShimmerLabel.h"
@interface QXMainHeaderView()
@property (nonatomic, strong) QXSeatHeaderView *userHeaderView;
@property (nonatomic, strong) UIImageView *sexImageView;
//@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) CKShimmerLabel *nameLabel;
@property (nonatomic, strong) UILabel *idLabel;
@property (nonatomic, strong) UIButton *idCopyBtn;
@property (nonatomic, strong) UIView *userTagView;
@property (nonatomic, strong) UIView *userHomeView;
@property (nonatomic, strong) UILabel *userHomeTitleLabel;
@property (nonatomic, strong) UIImageView *userHomeImageView;
@property (nonatomic, strong) UIButton *userHomeBtn;
@property (nonatomic, strong) UIImageView *useCodeImageView;
//@property (nonatomic, strong) UIButton *leftBtn;
//@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) UIButton *roomBtn;
///
@property (nonatomic, strong) NSMutableArray *iconArray;
@end
@implementation QXMainHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
MJWeakSelf
self.userHeaderView = [[QXSeatHeaderView alloc] initWithFrame:CGRectMake(16, 40, 68, 68)];
[self.userHeaderView addTapBlock:^(id _Nonnull obj) {
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didClickOptionType:)]) {
[weakSelf.delegate didClickOptionType:QXMainHeaderOptionTypeGotoHome];
}
}];
[self addSubview:self.userHeaderView];
self.sexImageView = [[UIImageView alloc] init];
[self addSubview:self.sexImageView];
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.bottom.equalTo(self.userHeaderView);
make.height.width.mas_equalTo(16);
}];
// self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userHeaderView.right+6, self.userHeaderView.top, self.width-self.userHeaderView.right-16-6, 23)];
self.nameLabel = [[CKShimmerLabel alloc] initWithFrame:CGRectMake(self.userHeaderView.right+6, self.userHeaderView.top, self.width-self.userHeaderView.right-16-6, 23)];
self.nameLabel.shimmerWidth = 20;
self.nameLabel.shimmerRadius = 20;
self.nameLabel.shimmerColor = [UIColor yellowColor];
self.nameLabel.repeat = YES;
self.nameLabel.textColor = QXConfig.textColor;
self.nameLabel.font = [UIFont boldSystemFontOfSize:18];
// [self.nameLabel startShimmer];
[self addSubview:self.nameLabel];
self.idLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.userHeaderView.right+6, self.nameLabel.bottom+5, 80, 17)];
self.idLabel.textColor = RGB16(0x666666);
self.idLabel.font = [UIFont systemFontOfSize:12];
self.idLabel.text = @"ID:";
[self addSubview:self.idLabel];
self.useCodeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_usercode_isLiang"]];
self.useCodeImageView.frame = CGRectMake(0, 0, 32, 13);
self.useCodeImageView.hidden = YES;
[self addSubview:self.useCodeImageView];
self.idCopyBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.idLabel.right, 0, 25, 25)];
self.idCopyBtn.centerY = self.idLabel.centerY;
[self.idCopyBtn setImage:[UIImage imageNamed:@"id_copy"] forState:(UIControlStateNormal)];
[self.idCopyBtn addTarget:self action:@selector(idCopyClick) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.idCopyBtn];
self.userHomeView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60-16, 0, 60, 23)];
self.userHomeView.layer.cornerRadius = self.userHomeView.height/2.0;
self.userHomeView.layer.shadowColor = [UIColor grayColor].CGColor;
self.userHomeView.layer.shadowOpacity = 0.3;
self.userHomeView.layer.shadowOffset = CGSizeMake(0, 2);
self.userHomeView.layer.shadowRadius = 2;
self.userHomeView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.userHomeView.bounds cornerRadius:self.userHomeView.layer.cornerRadius].CGPath;
self.userHomeView.layer.masksToBounds = NO;
self.userHomeView.centerY = self.userHeaderView.centerY;
self.userHomeView.backgroundColor = [UIColor whiteColor];
[self addSubview:self.userHomeView];
self.userHomeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrowRight"]];
self.userHomeImageView.frame = CGRectMake(self.userHomeView.width-10-16, (23-16)/2.0, 16, 16);
[self.userHomeView addSubview:self.userHomeImageView];
self.userHomeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 20, 20)];
self.userHomeTitleLabel.text = QXText(@"编辑");
self.userHomeTitleLabel.font = [UIFont systemFontOfSize:12];
self.userHomeTitleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
[self.userHomeTitleLabel sizeToFit];
self.userHomeTitleLabel.x = 10;
self.userHomeTitleLabel.y =( self.userHomeView.height - self.userHomeTitleLabel.height)/2.0;
[self.userHomeView addSubview:self.userHomeTitleLabel];
self.userHomeBtn = [[UIButton alloc] initWithFrame:self.userHomeView.bounds];
[self.userHomeBtn addTarget:self action:@selector(gotoUserHomePageClick) forControlEvents:(UIControlEventTouchUpInside)];
[self.userHomeView addSubview:self.userHomeBtn];
// NSArray* nameArr = @[
// QXText(@"关注"), QXText(@"粉丝"), QXText(@"好友"), QXText(@"访客")
// ];
NSArray* nameArr = @[
QXText(@"关注"), QXText(@"粉丝"),QXText(@"访客")
];
CGFloat width = (SCREEN_WIDTH-32)/4;
for (int i = 0; i < nameArr.count; i ++) {
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16+width*i, self.userHeaderView.bottom+19, width, 22)];
titleLabel.textColor = RGB16(0x666666);
titleLabel.font = [UIFont systemFontOfSize:12];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = nameArr[i];
[titleLabel sizeToFit];
titleLabel.x = 16+width*i;
titleLabel.y = self.userHeaderView.bottom+16;
titleLabel.height = 22;
[self addSubview:titleLabel];
UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.right+5, titleLabel.top, width-10-titleLabel.width, 22)];
countLabel.textAlignment = NSTextAlignmentCenter;
countLabel.textColor = QXConfig.textColor;
countLabel.tag = 10 + i;
countLabel.font = [UIFont boldSystemFontOfSize:16];
countLabel.text = @"0";
countLabel.centerY = titleLabel.centerY;
[self addSubview:countLabel];
UIControl *c = [[UIControl alloc] initWithFrame:CGRectMake(titleLabel.left, titleLabel.top-10, width, titleLabel.height+20)];
c.tag = 20 + i;
[c addTarget:self action:@selector(viewClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:c];
}
// self.leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(16, self.userHeaderView.bottom+54, width*2-7.5, 67)];
// [self.leftBtn setBackgroundImage:[UIImage imageNamed:@"start_live"] forState:(UIControlStateNormal)];
// [self.leftBtn addTarget:self action:@selector(leftAction) forControlEvents:(UIControlEventTouchUpInside)];
// [self addSubview:self.leftBtn];
2025-09-24 09:28:49 +08:00
//
2025-09-22 18:48:29 +08:00
// self.rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.leftBtn.right+7.5, self.userHeaderView.bottom+54, self.leftBtn.width, 67)];
// [self.rightBtn setBackgroundImage:[UIImage imageNamed:@"become_anchor"] forState:(UIControlStateNormal)];
// [self.rightBtn addTarget:self action:@selector(rightAction) forControlEvents:(UIControlEventTouchUpInside)];
// [self addSubview:self.rightBtn];
self.roomBtn = [[UIButton alloc] initWithFrame:CGRectMake(16, self.userHeaderView.bottom+54, self.width-32, ScaleWidth(67))];
[self.roomBtn setBackgroundImage:[UIImage imageNamed:@"mine_header_room"] forState:(UIControlStateNormal)];
[self.roomBtn addTarget:self action:@selector(roomAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.roomBtn];
}
-(void)viewClick:(UIControl*)sender{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) {
[self.delegate didClickOptionType:sender.tag];
}
}
-(void)roomAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) {
[self.delegate didClickOptionType:QXMainHeaderOptionTypeRoom];
}
}
-(void)leftAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) {
[self.delegate didClickOptionType:QXMainHeaderOptionTypeStartLive];
}
}
-(void)rightAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) {
[self.delegate didClickOptionType:QXMainHeaderOptionTypeRealName];
}
}
-(void)gotoUserHomePageClick{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickOptionType:)]) {
[self.delegate didClickOptionType:QXMainHeaderOptionTypeGotoEdit];
}
}
-(void)setUserModel:(QXUserModel *)userModel{
_userModel = userModel;
[self.userHeaderView setHeadIcon:userModel.avatar dress:userModel.dress];
self.nameLabel.text = userModel.nickname;
self.idLabel.text = [NSString stringWithFormat:@"ID:%@",userModel.user_code];
UILabel *followLabel = [self viewWithTag:10];
UILabel *fansLabel = [self viewWithTag:11];
UILabel *lookLabel = [self viewWithTag:12];
followLabel.text = userModel.follow_num;
fansLabel.text = userModel.fans_num;
lookLabel.text = userModel.look_me_num;
for (UIView*v in self.iconArray) {
[v removeFromSuperview];
}
for (int i = 0;i<userModel.icon.count;i++) {
NSString*icon = userModel.icon[i];
2025-09-24 09:28:49 +08:00
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.nameLabel.left+i*UserIconWidth, self.idLabel.bottom+5, UserIconWidth, UserIconHeight)];
2025-09-22 18:48:29 +08:00
[imageView sd_setImageWithURL:[NSURL URLWithString:icon]];
[self addSubview:imageView];
[self.iconArray addObject:imageView];
}
[self.idLabel sizeToFit];
if (userModel.is_use_code.intValue == 1) {
self.useCodeImageView.hidden = NO;
self.useCodeImageView.x = self.idLabel.right+5;
self.idCopyBtn.x = self.useCodeImageView.right;
self.useCodeImageView.centerY = self.idLabel.centerY;
}else{
self.useCodeImageView.hidden = YES;
self.idCopyBtn.x = self.idLabel.right;
}
UIImage *sexImage = [UIImage imageNamed:userModel.sex.intValue==1?@"user_sex_boy":@"user_sex_girl"];
self.sexImageView.image = sexImage;
}
-(void)idCopyClick{
UIPasteboard *p = [UIPasteboard generalPasteboard];
p.string = [NSString stringWithFormat:@"%@", self.userModel.user_code];
showToast(@"已复制");
}
-(NSMutableArray *)iconArray{
if (!_iconArray) {
_iconArray = [NSMutableArray array];
}
return _iconArray;
}
@end