Files
yinmeng-ios/xplan-ios/Main/Room/View/XPRoomOfflineViewController.m
2023-04-19 16:00:09 +08:00

252 lines
8.2 KiB
Objective-C

//
// XPRoomOfflineViewController.m
// xplan-ios
//
// Created by XY on 2023/4/19.
//
#import "XPRoomOfflineViewController.h"
#import "NetImageView.h"
#import "ThemeColor.h"
#import <Masonry/Masonry.h>
#import "XPMacro.h"
#import "UserInfoModel.h"
#import "XPMineUserInfoViewController.h"
@interface XPRoomOfflineViewController ()
/// 头像
@property (nonatomic, strong) NetImageView *avatarImageView;
///
@property (nonatomic, strong) UIStackView *nickStackVeiw;
/// 昵称
@property (nonatomic, strong) UILabel *nickLabel;
/// 性别
@property (nonatomic, strong) UIImageView *sexImageView;
///
@property (nonatomic, strong) UIStackView *offlineStackView;
/// 房主已下线
@property (nonatomic, strong) UILabel *offlineLabel;
/// 左线
@property (nonatomic, strong) UIView *leftLine;
/// 右线
@property (nonatomic, strong) UIView *rightLine;
/// 主页
@property (nonatomic, strong) UIButton *homeBtn;
/// 退出
@property (nonatomic, strong) UIButton *exitBtn;
@end
@implementation XPRoomOfflineViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - Private Method
- (void)initSubViews {
self.view.backgroundColor = [ThemeColor colorWithHexString:@"#1A1E40"];
[self.view addSubview:self.avatarImageView];
[self.view addSubview:self.nickStackVeiw];
[self.view addSubview:self.offlineStackView];
[self.view addSubview:self.homeBtn];
[self.view addSubview:self.exitBtn];
[self.nickStackVeiw addArrangedSubview:self.nickLabel];
[self.nickStackVeiw addArrangedSubview:self.sexImageView];
[self.offlineStackView addArrangedSubview:self.leftLine];
[self.offlineStackView addArrangedSubview:self.offlineLabel];
[self.offlineStackView addArrangedSubview:self.rightLine];
}
- (void)initSubViewConstraints {
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(kStatusBarHeight+60);
make.width.height.mas_equalTo(120);
}];
[self.nickStackVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(40);
make.centerX.mas_equalTo(self.view);
}];
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(14);
}];
[self.offlineStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.mas_equalTo(self.nickStackVeiw.mas_bottom).offset(100);
}];
[self.leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(60);
make.height.mas_equalTo(1);
}];
[self.rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(self.leftLine);
}];
[self.exitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-kSafeAreaBottomHeight-20);
make.left.mas_equalTo(40);
make.right.mas_equalTo(-40);
make.height.mas_equalTo(50);
}];
[self.homeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.height.mas_equalTo(self.exitBtn);
make.bottom.mas_equalTo(self.exitBtn.mas_top).offset(-15);
}];
}
#pragma mark - Event
- (void)homeBtnAction {
XPMineUserInfoViewController *vc = [[XPMineUserInfoViewController alloc] init];
vc.uid = self.userInfo.uid;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)exitBtnAction {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Getters And Setters
- (void)setUserInfo:(UserInfoModel *)userInfo {
_userInfo = userInfo;
self.avatarImageView.imageUrl = userInfo.avatar;
self.nickLabel.text = userInfo.nick;
if (userInfo.gender == GenderType_Female) {
self.sexImageView.image = [UIImage imageNamed:@"common_female"];
}else{
self.sexImageView.image = [UIImage imageNamed:@"common_male"];
}
}
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = 120.0/2;
_avatarImageView.userInteractionEnabled = YES;
_avatarImageView.layer.borderColor = UIColor.whiteColor.CGColor;
_avatarImageView.layer.borderWidth = 1;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(homeBtnAction)];
[_avatarImageView addGestureRecognizer:tap];
}
return _avatarImageView;
}
- (UIStackView *)nickStackVeiw {
if (!_nickStackVeiw) {
_nickStackVeiw = [[UIStackView alloc] init];
_nickStackVeiw.axis = UILayoutConstraintAxisHorizontal;
_nickStackVeiw.distribution = UIStackViewDistributionFill;
_nickStackVeiw.alignment = UIStackViewAlignmentCenter;
_nickStackVeiw.spacing = 4;
}
return _nickStackVeiw;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [[UILabel alloc] init];
_nickLabel.textColor = [UIColor whiteColor];
_nickLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
}
return _nickLabel;
}
- (UIImageView *)sexImageView {
if (!_sexImageView) {
_sexImageView = [[UIImageView alloc] init];
_sexImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _sexImageView;
}
- (UIStackView *)offlineStackView {
if (!_offlineStackView) {
_offlineStackView = [[UIStackView alloc] init];
_offlineStackView.axis = UILayoutConstraintAxisHorizontal;
_offlineStackView.distribution = UIStackViewDistributionEqualSpacing;
_offlineStackView.alignment = UIStackViewAlignmentCenter;
_offlineStackView.spacing = 10;
}
return _offlineStackView;
}
- (UILabel *)offlineLabel {
if (!_offlineLabel) {
_offlineLabel = [[UILabel alloc] init];
_offlineLabel.text = @"房主已下线";
_offlineLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_offlineLabel.textColor = [ThemeColor appMainColor];
}
return _offlineLabel;
}
- (UIView *)leftLine {
if (!_leftLine) {
_leftLine = [[UIView alloc] init];
_leftLine.backgroundColor = [[ThemeColor appMainColor] colorWithAlphaComponent:0.6];
}
return _leftLine;
}
- (UIView *)rightLine {
if (!_rightLine) {
_rightLine = [[UIView alloc] init];
_rightLine.backgroundColor = [[ThemeColor appMainColor] colorWithAlphaComponent:0.6];
}
return _rightLine;
}
- (UIButton *)homeBtn {
if (!_homeBtn) {
_homeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_homeBtn setTitle:@"主页" forState:UIControlStateNormal];
[_homeBtn setTitleColor:[ThemeColor appMainColor] forState:UIControlStateNormal];
_homeBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_homeBtn.layer.cornerRadius = 25;
_homeBtn.layer.borderWidth = 1;
_homeBtn.layer.borderColor = [ThemeColor appMainColor].CGColor;
_homeBtn.clipsToBounds = YES;
[_homeBtn addTarget:self action:@selector(homeBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _homeBtn;
}
- (UIButton *)exitBtn {
if (!_exitBtn) {
_exitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_exitBtn setTitle:@"退出" forState:UIControlStateNormal];
[_exitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_exitBtn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_exitBtn.layer.cornerRadius = 25;
_exitBtn.layer.borderWidth = 1;
_exitBtn.layer.borderColor = [UIColor whiteColor].CGColor;
_exitBtn.clipsToBounds = YES;
[_exitBtn addTarget:self action:@selector(exitBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _exitBtn;
}
@end