// // XPNewHomeHeaderView.m // xplan-ios // // Created by XY on 2023/3/3. // #import "XPNewHomeHeaderView.h" ///Third #import ///Tool #import "XPMacro.h" #import "ThemeColor.h" @interface XPNewHomeHeaderView() /// 交友派对 @property (nonatomic, strong) UIButton *partyView; /// 小游戏 @property (nonatomic, strong) UIButton *gameView; /// 听电台 @property (nonatomic, strong) UIButton *radioView; /// 一键匹配 @property (nonatomic, strong) UIButton *matchView; /// 热门 @property (nonatomic, strong) UIImageView *hotView; @property (nonatomic, strong) UILabel *hotTextLabel; @property (nonatomic, strong) UIView *messageView; @end @implementation XPNewHomeHeaderView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { self.backgroundColor = [UIColor clearColor]; [self addSubview:self.partyView]; [self addSubview:self.gameView]; [self addSubview:self.radioView]; [self addSubview:self.matchView]; [self addSubview:self.hotView]; [self.hotView addSubview:self.hotTextLabel]; [self.hotView addSubview:self.messageView]; } - (void)initSubViewConstraints { CGFloat partyWidth = 94.0*kScreenScale; CGFloat partyHeight = 120.0/94.0*partyWidth; [self.partyView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.top.mas_equalTo(15); make.width.mas_equalTo(partyWidth); make.height.mas_equalTo(partyHeight); }]; CGFloat gameWidth = (KScreenWidth - 15 -partyWidth - 8 - 3 -15)/2.0; CGFloat gameHeight = 56.0/120.0*gameWidth; [self.gameView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.partyView.mas_right).offset(15); make.top.mas_equalTo(self.partyView); make.width.mas_equalTo(gameWidth); make.height.mas_equalTo(gameHeight); }]; [self.radioView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.gameView.mas_right).offset(3); make.top.mas_equalTo(self.partyView); make.width.mas_equalTo(gameWidth); make.height.mas_equalTo(gameHeight); }]; CGFloat matchWidth = KScreenWidth - 15 - partyWidth - 8 - 15; CGFloat matchHeight = 56.0/243.0*matchWidth; [self.matchView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.gameView); make.bottom.mas_equalTo(self.partyView); make.width.mas_equalTo(matchWidth); make.height.mas_equalTo(matchHeight); }]; CGFloat hotHeight = 72.0*kScreenScale; [self.hotView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(hotHeight); make.top.mas_equalTo(self.partyView.mas_bottom).offset(20); }]; [self.hotTextLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.mas_equalTo(0); make.width.mas_equalTo(70); make.height.mas_equalTo(self.hotView.mas_height).multipliedBy(0.5); }]; [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(0); make.height.mas_equalTo(self.hotView.mas_height).multipliedBy(0.5); }]; } /// 获取headerView的高度 + (NSUInteger)getHeaderViewHeight { CGFloat height = 15; CGFloat partyWidth = 94.0*kScreenScale; CGFloat partyHeight = 120.0/94.0*partyWidth; height += partyHeight; height += 20; CGFloat hotHeight = 72.0*kScreenScale; height += hotHeight; height += 15; return (NSUInteger)height; } #pragma mark - Event Response - (void)partyViewAction { if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewPartyAction)]) { [self.delegate homeHeaderViewPartyAction]; } } - (void)gameViewAction { if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewGameAction)]) { [self.delegate homeHeaderViewGameAction]; } } - (void)radioViewAction { if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewRadioAction)]) { [self.delegate homeHeaderViewRadioAction]; } } - (void)matchViewAction { if (self.delegate && [self.delegate respondsToSelector:@selector(homeHeaderViewMatchAction)]) { [self.delegate homeHeaderViewMatchAction]; } } #pragma mark - Getters And Setters - (UIButton *)partyView { if (!_partyView) { _partyView = [UIButton buttonWithType:UIButtonTypeCustom]; [_partyView setBackgroundImage:[UIImage imageNamed:@"home_head_party"] forState:UIControlStateNormal]; [_partyView addTarget:self action:@selector(partyViewAction) forControlEvents:UIControlEventTouchUpInside]; } return _partyView; } - (UIButton *)gameView { if (!_gameView) { _gameView = [UIButton buttonWithType:UIButtonTypeCustom]; [_gameView setBackgroundImage:[UIImage imageNamed:@"home_head_game"] forState:UIControlStateNormal]; [_gameView addTarget:self action:@selector(gameViewAction) forControlEvents:UIControlEventTouchUpInside]; } return _gameView; } - (UIButton *)radioView { if (!_radioView) { _radioView = [UIButton buttonWithType:UIButtonTypeCustom]; [_radioView setBackgroundImage:[UIImage imageNamed:@"home_head_radio"] forState:UIControlStateNormal]; [_radioView addTarget:self action:@selector(radioViewAction) forControlEvents:UIControlEventTouchUpInside]; } return _radioView; } - (UIButton *)matchView { if (!_matchView) { _matchView = [UIButton buttonWithType:UIButtonTypeCustom]; [_matchView setBackgroundImage:[UIImage imageNamed:@"home_head_match"] forState:UIControlStateNormal]; [_matchView addTarget:self action:@selector(matchViewAction) forControlEvents:UIControlEventTouchUpInside]; } return _matchView; } - (UIImageView *)hotView { if (!_hotView) { _hotView = [[UIImageView alloc] init]; _hotView.image = [UIImage imageNamed:@"home_hot_bg"]; _hotView.userInteractionEnabled = YES; } return _hotView; } - (UILabel *)hotTextLabel { if (_hotTextLabel) { _hotTextLabel = [[UILabel alloc] init]; _hotTextLabel.textColor = [ThemeColor mainTextColor]; _hotTextLabel.text = @"热门"; _hotTextLabel.textAlignment = NSTextAlignmentCenter; _hotTextLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold]; } return _hotTextLabel; } - (UIView *)messageView { if (!_messageView) { _messageView = [[UIView alloc] init]; } return _messageView; } @end