// // XPMonentsPublishTopicView.m // xplan-ios // // Created by 冯硕 on 2022/8/16. // #import "XPMonentsPublishTopicView.h" ///Third #import ///Tool #import "ThemeColor.h" #import "UIView+Corner.h" #import "UIButton+EnlargeTouchArea.h" ///Model #import "MonentsTopicModel.h" @interface XPMonentsPublishTopicView () ///容器 @property (nonatomic,strong) UIStackView *stackView; ///添加话题 @property (nonatomic,strong) UIButton *addTopicButton; ///重新选择 @property (nonatomic,strong) UIButton *againButton; ///话题的view @property (nonatomic,strong) UIView * topicView; ///显示话题内容 @property (nonatomic,strong) UILabel *titleLabel; ///关闭按钮 @property (nonatomic,strong) UIButton *closeButton; ///占位 @property (nonatomic,strong) UIView * placeView; @end @implementation XPMonentsPublishTopicView - (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.stackView]; [self.stackView addArrangedSubview:self.addTopicButton]; [self.stackView addArrangedSubview:self.topicView]; [self.stackView addArrangedSubview:self.placeView]; [self.stackView addArrangedSubview:self.againButton]; [self.topicView addSubview:self.titleLabel]; [self.topicView addSubview:self.closeButton]; } - (void)initSubViewConstraints { [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self); make.height.mas_equalTo(20); make.centerY.mas_equalTo(self); }]; [self.addTopicButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(60); }]; [self.topicView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(120); }]; [self.againButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(60); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.topicView).offset(5); make.centerY.mas_equalTo(self.topicView); }]; [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.topicView).offset(-7); make.size.mas_equalTo(CGSizeMake(18, 18)); make.centerY.mas_equalTo(self.topicView); }]; } #pragma mark - Event Response - (void)addTopicButtonAction:(UIButton *)sender { if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsPublishTopicView:didClickChooseTopic:)]) { [self.delegate xPMonentsPublishTopicView:self didClickChooseTopic:sender]; } } - (void)closeButtonAction:(UIButton *)sender { if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsPublishTopicView:didClickCloseButton:)]) { [self.delegate xPMonentsPublishTopicView:self didClickCloseButton:sender]; } } #pragma mark - Getters And Setters - (void)setTopicInfo:(MonentsTopicModel *)topicInfo { _topicInfo = topicInfo; if (_topicInfo) { self.addTopicButton.hidden = YES; self.topicView.hidden = NO; self.againButton.hidden = NO; self.titleLabel.text = _topicInfo.worldName; } else { self.addTopicButton.hidden = NO; self.topicView.hidden = YES; self.againButton.hidden= YES; } } - (UIStackView *)stackView { if (!_stackView) { _stackView = [[UIStackView alloc] init]; _stackView.axis = UILayoutConstraintAxisHorizontal; _stackView.distribution = UIStackViewDistributionFill; _stackView.alignment = UIStackViewAlignmentFill; _stackView.spacing = 0; } return _stackView; } - (UIButton *)addTopicButton { if (!_addTopicButton) { _addTopicButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_addTopicButton setTitle:@"添加话题" forState:UIControlStateNormal]; [_addTopicButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal]; _addTopicButton.titleLabel.font = [UIFont systemFontOfSize:12]; [_addTopicButton setBackgroundColor:[UIColor whiteColor]]; _addTopicButton.layer.masksToBounds = YES; _addTopicButton.layer.cornerRadius = 10; [_addTopicButton addTarget:self action:@selector(addTopicButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _addTopicButton; } - (UIButton *)againButton { if (!_againButton) { _againButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_againButton setTitle:@"重新选择" forState:UIControlStateNormal]; [_againButton setTitleColor:[ThemeColor secondTextColor] forState:UIControlStateNormal]; _againButton.titleLabel.font = [UIFont systemFontOfSize:12]; [_againButton addTarget:self action:@selector(addTopicButtonAction:) forControlEvents:UIControlEventTouchUpInside]; _againButton.hidden = YES; } return _againButton; } - (UIView *)topicView { if (!_topicView) { _topicView = [[UIView alloc] init]; _topicView.backgroundColor = [UIColor clearColor]; _topicView.backgroundColor = [ThemeColor appMainColor]; _topicView.layer.masksToBounds = YES; _topicView.hidden = YES; [_topicView setCornerWithLeftTopCorner:10 rightTopCorner:5 bottomLeftCorner:10 bottomRightCorner:10 size:CGSizeMake(120, 20)]; } return _topicView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:13]; _titleLabel.textColor = [UIColor whiteColor]; } return _titleLabel; } - (UIButton *)closeButton { if (!_closeButton) { _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeButton setImage:[UIImage imageNamed:@"monents_publish_delete"] forState:UIControlStateNormal]; [_closeButton setImage:[UIImage imageNamed:@"monents_publish_delete"] forState:UIControlStateSelected]; [_closeButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10]; [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _closeButton; } - (UIView *)placeView { if (!_placeView) { _placeView = [[UIView alloc] init]; _placeView.backgroundColor = [UIColor clearColor]; } return _placeView; } @end