Files
peko-ios/YuMi/Modules/YMNewHome/View/CustomView/XPHomeRecommendOtherRoomView.m
2023-09-12 18:08:46 +08:00

186 lines
6.0 KiB
Objective-C

//
// XPHomeRecommendOtherRoomView.m
// xplan-ios
//
// Created by 冯硕 on 2022/3/3.
//
#import "XPHomeRecommendOtherRoomView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "NetImageView.h"
#import "TTPopup.h"
#import "UIImage+Utils.h"
///Model
#import "HomeMenuSourceModel.h"
@interface XPHomeRecommendOtherRoomView ()
///背景
@property (nonatomic,strong) UIView * contentView;
///标题
@property (nonatomic,strong) UILabel *titleLabel;
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///房间标题
@property (nonatomic,strong) UILabel *roomTitleLabel;
///加入房间
@property (nonatomic,strong) UIButton *enterRoomButton;
///关闭
@property (nonatomic,strong) UIButton *closeButton;
@end
@implementation XPHomeRecommendOtherRoomView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.contentView];
[self addSubview:self.closeButton];
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.avatarImageView];
[self.contentView addSubview:self.roomTitleLabel];
[self.contentView addSubview:self.enterRoomButton];
}
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(300);
make.bottom.mas_equalTo(self.closeButton.mas_bottom);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(self);
make.height.mas_equalTo(299);
}];
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(30, 30));
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(self.contentView.mas_bottom).offset(32);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(19);
make.top.mas_equalTo(self).offset(12);
}];
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(16);
make.size.mas_equalTo(CGSizeMake(108, 108));
make.centerX.mas_equalTo(self.contentView);
}];
[self.roomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(73);
make.top.mas_equalTo(self.avatarImageView.mas_bottom).offset(24);
}];
[self.enterRoomButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(60);
make.bottom.mas_equalTo(self.contentView).offset(-24);
make.height.mas_equalTo(40);
}];
}
#pragma mark - Event Response
- (void)enterRoomButtonAction:(UIButton *)sender {
[TTPopup dismiss];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeRecommendOtherRoomView:didClickEnterRoom:)]) {
[self.delegate xPHomeRecommendOtherRoomView:self didClickEnterRoom:self.roomInfo];
}
}
- (void)closeButtonAction:(UIButton *)sender {
[TTPopup dismiss];
}
#pragma mark - Getters And Setters
- (void)setRoomInfo:(HomeMenuSourceModel *)roomInfo {
_roomInfo = roomInfo;
if (_roomInfo) {
self.roomTitleLabel.text = _roomInfo.title;
self.avatarImageView.imageUrl = _roomInfo.avatar;
}
}
- (UIView *)contentView {
if (!_contentView) {
_contentView = [[UIView alloc] init];
_contentView.backgroundColor = [UIColor whiteColor];
_contentView.layer.masksToBounds = YES;
_contentView.layer.cornerRadius = 12;
_contentView.layer.shadowOffset = CGSizeMake(4, 4);
_contentView.layer.shadowColor = UIColorRGBAlpha(0xEBEEF3, 0.7).CGColor;
}
return _contentView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = YMLocalizedString(@"XPHomeRecommendOtherRoomView0");
_titleLabel.font = [UIFont boldSystemFontOfSize:16];
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
}
return _titleLabel;
}
- (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 = 8;
}
return _avatarImageView;
}
- (UILabel *)roomTitleLabel {
if (!_roomTitleLabel) {
_roomTitleLabel = [[UILabel alloc] init];
_roomTitleLabel.font = [UIFont systemFontOfSize:14];
_roomTitleLabel.numberOfLines = 2;
_roomTitleLabel.textColor = [DJDKMIMOMColor mainTextColor];
_roomTitleLabel.textAlignment = NSTextAlignmentCenter;
}
return _roomTitleLabel;
}
- (UIButton *)enterRoomButton {
if (!_enterRoomButton) {
_enterRoomButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_enterRoomButton setTitle:YMLocalizedString(@"XPHomeRecommendOtherRoomView1") forState:UIControlStateNormal];
[_enterRoomButton setTitleColor:[DJDKMIMOMColor confirmButtonTextColor] forState:UIControlStateNormal];
_enterRoomButton.titleLabel.font = [UIFont systemFontOfSize:15];
[_enterRoomButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
_enterRoomButton.layer.masksToBounds = YES;
_enterRoomButton.layer.cornerRadius = 20;
[_enterRoomButton addTarget:self action:@selector(enterRoomButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _enterRoomButton;
}
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeButton setImage:[UIImage imageNamed:@"common_close_white"] forState:UIControlStateNormal];
[_closeButton setImage:[UIImage imageNamed:@"common_close_white"] forState:UIControlStateSelected];
[_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
@end