123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- //
- // YMInputPopupView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/25.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMInputPopupView.h"
- @interface YMInputPopupView ()<YYTextViewDelegate>
- /** 标题标签*/
- @property (nonatomic, strong) UILabel *titleLb;
- /** 内容文本框*/
- @property (nonatomic, strong) YYTextView *contentTextView;
- /** 上限标签*/
- @property (nonatomic, strong) UILabel *limitLb;
- /** 按钮视图*/
- @property (nonatomic, strong) UIView *buttonView;
- /** 取消按钮*/
- @property (nonatomic, strong) UIButton *cancelBtn;
- /** 确认按钮*/
- @property (nonatomic, strong) UIButton *confirmBtn;
- /** 单确认按钮*/
- @property (nonatomic, strong) UIButton *singleConfirmBtn;
- @end
- @implementation YMInputPopupView
- #pragma mark - private
- - (void)ym_setupViews{
-
- self.backgroundColor = HexColorFromRGB(0xFFFFFF);
-
- self.titleText = @"提示";
- self.titleFont = LCBoldFont(18);
- self.titleColor = HexColorFromRGB(0x333333);
-
- self.cancelBgColor = HexColorFromRGB(0xF5F5F5);
- self.confirmBgColor = HexColorFromRGB(0xF888E7);
-
- self.cancelTitleColor = HexColorFromRGB(0x555555);
- self.confirmTitleColor = HexColorFromRGB(0xFFFFFF);
-
- self.cancelFont = LCFont(14);
- self.confirmFont = LCFont(14);
-
- self.cancelTitle = @"取消";
- self.confirmTitle = @"确定";
-
- self.cancelRadius = 10;
- self.confirmRadius = 10;
-
- self.cancelBorderColor = HexColorFromRGB(0xF5F5F5);
- self.confirmBorderColor = HexColorFromRGB(0xF888E7);
-
- self.cancelBorderWidth = 0.5;
- self.confirmBorderWidth = 0.5;
-
- self.maxLength = 15;
-
- [self addSubview:self.titleLb];
- [self addSubview:self.contentTextView];
- [self addSubview:self.limitLb];
- [self addSubview:self.buttonView];
- [self.buttonView addSubview:self.cancelBtn];
- [self.buttonView addSubview:self.confirmBtn];
- [self addSubview:self.singleConfirmBtn];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(15));
- make.left.equalTo(self).offset(adapt(20));
- make.right.equalTo(self).offset(adapt(-20));
- make.height.mas_equalTo(adapt(20));
- }];
-
- [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(10));
- make.left.equalTo(self).offset(adapt(20));
- make.right.equalTo(self).offset(adapt(-20));
- make.height.mas_equalTo(adapt(160));
- }];
-
- [self.limitLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentTextView.mas_bottom).offset(adapt(10));
- make.right.equalTo(self.contentTextView.mas_right);
- make.height.mas_equalTo(adapt(15));
- }];
-
- [self.buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.limitLb.mas_bottom).offset(adapt(10));
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self).offset(adapt(-15)).priorityHigh();
- }];
-
- NSArray *btnArr = @[self.cancelBtn,self.confirmBtn];
-
- // 实现masonry水平固定控件宽度方法
- // axisType 横排还是竖排
- // fixedSpacing 两个控件间隔
- // leadSpacing 第一个控件与边缘的间隔
- // tailSpacing 最后一个控件与边缘的间隔
- [btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:adapt(15) leadSpacing:adapt(20) tailSpacing:adapt(20)];
-
- // 设置array的垂直方向的约束
- [btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.buttonView);
- make.bottom.equalTo(self.buttonView);
- make.height.mas_equalTo(adapt(38));
- }];
-
- [self.singleConfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.limitLb.mas_bottom).offset(adapt(10));
- make.left.equalTo(self).offset(adapt(45));
- make.right.equalTo(self).offset(adapt(-45));
- make.bottom.equalTo(self).offset(adapt(-15)).priorityHigh();
- make.height.mas_equalTo(adapt(38));
- }];
- [super updateConstraints];
- }
- - (void)configutationWithContentText:(NSString*)contentText ofInputHeight:(CGFloat)inputHeight IsHideTitle:(BOOL)isHideTitle IsHideSingleButton:(BOOL)isHideSingleButton{
-
- self.contentTextView.text = contentText;
-
- [self judgeTitleIsHide:isHideTitle];
-
- [self judgeSingleButtonIsHide:isHideSingleButton];
-
- [self.contentTextView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(inputHeight);
- }];
-
- CGFloat titleLbHeight = [self.titleLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat contentTextViewHeight = [self.contentTextView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat limitLbHeight = [self.limitLb systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- CGFloat buttonViewHeight = isHideSingleButton ? [self.singleConfirmBtn systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height : [self.buttonView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
-
- self.frame = CGRectMake(0, 0, kFrameWidth*0.8, adapt(15) + (isHideTitle ? 0 : titleLbHeight + adapt(10)) + contentTextViewHeight + adapt(10) + limitLbHeight + adapt(10) + buttonViewHeight + adapt(15));
- }
- #pragma mark - 判断标题是否隐藏
- - (void)judgeTitleIsHide:(BOOL)isHide{
-
- self.titleLb.hidden = isHide;
-
- if (isHide) {
- [self.titleLb mas_remakeConstraints:^(MASConstraintMaker *make) {
-
- }];
-
- [self.contentTextView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(15));
- }];
- }else{
- [self.titleLb mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(15));
- make.left.equalTo(self).offset(adapt(20));
- make.right.equalTo(self).offset(adapt(-20));
- }];
-
- [self.contentTextView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLb.mas_bottom).offset(adapt(10));
- }];
- }
- }
- #pragma mark - 判断单按钮是否隐藏
- - (void)judgeSingleButtonIsHide:(BOOL)isHide{
-
- self.singleConfirmBtn.hidden = isHide;
-
- if (isHide) {
-
- self.buttonView.hidden = NO;
-
- }else{
-
- self.buttonView.hidden = YES;
-
- }
- }
- - (void)setTitleText:(NSString *)titleText{
- _titleText = titleText;
- self.titleLb.text = titleText;
- }
- - (void)setTitleFont:(UIFont *)titleFont{
- _titleFont = titleFont;
- self.titleLb.font = titleFont;
- }
- - (void)setTitleColor:(UIColor *)titleColor{
- _titleColor = titleColor;
- self.titleLb.textColor = titleColor;
-
- }
- - (void)setCancelBgColor:(UIColor *)cancelBgColor{
- _cancelBgColor = cancelBgColor;
- _cancelBtn.backgroundColor = cancelBgColor;
- }
- - (void)setConfirmBgColor:(UIColor *)confirmBgColor{
- _confirmBgColor = confirmBgColor;
- self.confirmBtn.backgroundColor = confirmBgColor;
- self.singleConfirmBtn.backgroundColor = confirmBgColor;
- }
- - (void)setCancelTitleColor:(UIColor *)cancelTitleColor{
- _cancelTitleColor = cancelTitleColor;
- [self.cancelBtn setTitleColor:cancelTitleColor forState:UIControlStateNormal];
- }
- - (void)setConfirmTitleColor:(UIColor *)confirmTitleColor{
- _confirmTitleColor = confirmTitleColor;
- [self.confirmBtn setTitleColor:confirmTitleColor forState:UIControlStateNormal];
- [self.singleConfirmBtn setTitleColor:confirmTitleColor forState:UIControlStateNormal];
- }
- - (void)setCancelFont:(UIFont *)cancelFont{
- _cancelFont = cancelFont;
- self.cancelBtn.titleLabel.font = cancelFont;
- }
- - (void)setConfirmFont:(UIFont *)confirmFont{
- _confirmFont = confirmFont;
- self.confirmBtn.titleLabel.font = confirmFont;
- self.singleConfirmBtn.titleLabel.font = confirmFont;
- }
- - (void)setCancelTitle:(NSString *)cancelTitle{
- _cancelTitle = cancelTitle;
- [self.cancelBtn setTitle:cancelTitle forState:UIControlStateNormal];
- }
- - (void)setConfirmTitle:(NSString *)confirmTitle{
- _confirmTitle = confirmTitle;
- [self.confirmBtn setTitle:confirmTitle forState:UIControlStateNormal];
- [self.singleConfirmBtn setTitle:confirmTitle forState:UIControlStateNormal];
- }
- - (void)setCancelRadius:(CGFloat)cancelRadius{
- _cancelRadius = cancelRadius;
- self.cancelBtn.layer.cornerRadius = cancelRadius;
- }
- - (void)setConfirmRadius:(CGFloat)confirmRadius{
- _confirmRadius = confirmRadius;
- self.confirmBtn.layer.cornerRadius = confirmRadius;
- self.singleConfirmBtn.layer.cornerRadius = confirmRadius;
- }
- - (void)setCancelBorderColor:(UIColor *)cancelBorderColor{
- _cancelBorderColor = cancelBorderColor;
- self.cancelBtn.layer.borderColor = cancelBorderColor.CGColor;
- }
- - (void)setConfirmBorderColor:(UIColor *)confirmBorderColor{
- _confirmBorderColor = confirmBorderColor;
- self.confirmBtn.layer.borderColor = confirmBorderColor.CGColor;
- self.singleConfirmBtn.layer.borderColor = confirmBorderColor.CGColor;
- }
- - (void)setCancelBorderWidth:(CGFloat)cancelBorderWidth{
- _cancelBorderWidth = cancelBorderWidth;
- self.cancelBtn.layer.borderWidth = cancelBorderWidth;
- }
- - (void)setConfirmBorderWidth:(CGFloat)confirmBorderWidth{
- _confirmBorderWidth = confirmBorderWidth;
- self.confirmBtn.layer.borderWidth = confirmBorderWidth;
- self.singleConfirmBtn.layer.borderWidth = confirmBorderWidth;
- }
- - (void)setMaxLength:(NSInteger)maxLength{
- _maxLength = maxLength;
- self.limitLb.text = stringFormat(@"0/%ld",maxLength);
- }
- - (void)setTextAlignment:(NSTextAlignment)textAlignment{
- _textAlignment = textAlignment;
- self.contentTextView.textAlignment = textAlignment;
- }
- - (void)setPlaceholderText:(NSString *)placeholderText{
- _placeholderText = placeholderText;
- self.contentTextView.placeholderText = placeholderText;
- }
- - (void)textViewDidChangeSelection:(YYTextView *)textView{
- NSString *string = textView.text;
- NSInteger maxLength = self.maxLength;
- //获取高亮部分
- YYTextRange *selectedRange = [textView valueForKey:@"_markedTextRange"];
- NSRange range = [selectedRange asRange];
- NSString *realString = [string substringWithRange:NSMakeRange(0, string.length - range.length)];
- if (realString.length >= maxLength){
- textView.text = [realString substringWithRange:NSMakeRange(0, maxLength)];
- }
- self.limitLb.text = stringFormat(@"%ld/%ld",realString.length,self.maxLength);
- }
- - (UILabel *)titleLb{
- if (!_titleLb) {
- _titleLb = [[UILabel alloc]init];
- _titleLb.font = self.titleFont;
- _titleLb.textColor = self.titleColor;
- _titleLb.textAlignment = NSTextAlignmentCenter;
- _titleLb.text = self.titleText;
- }
- return _titleLb;
- }
- - (YYTextView *)contentTextView{
- if (!_contentTextView) {
- _contentTextView = [[YYTextView alloc]init];
- _contentTextView.delegate = self;
- _contentTextView.font = LCFont(15);
- _contentTextView.textColor = HexColorFromRGB(0x000000);
- _contentTextView.placeholderText = @"请输入内容";
- _contentTextView.backgroundColor = HexColorFromRGB(0xF6F6F6);
- _contentTextView.layer.cornerRadius = adapt(10);
- }
- return _contentTextView;
- }
- - (UILabel *)limitLb{
- if (!_limitLb) {
- _limitLb = [[UILabel alloc]init];
- _limitLb.font = LCFont(11);
- _limitLb.textColor = HexColorFromRGB(0x333333);
- _limitLb.textAlignment = NSTextAlignmentRight;
- _limitLb.text = stringFormat(@"0/%ld",self.maxLength);
- }
- return _limitLb;
- }
- - (UIView *)buttonView{
- if (!_buttonView) {
- _buttonView = [[UIView alloc]init];
- }
- return _buttonView;
- }
- - (UIButton *)cancelBtn {
- if(!_cancelBtn){
- _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _cancelBtn.backgroundColor = self.cancelBgColor;
- _cancelBtn.titleLabel.font = self.cancelFont;
- [_cancelBtn setTitleColor:self.cancelTitleColor forState:UIControlStateNormal];
- [_cancelBtn setTitle:self.cancelTitle forState:UIControlStateNormal];
- _cancelBtn.layer.cornerRadius = self.cancelRadius;
- _cancelBtn.layer.borderWidth = self.cancelBorderWidth;
- _cancelBtn.layer.borderColor = self.cancelBorderColor.CGColor;
- WS(weakSelf)
- [[[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(NO,@"");
- }
- }];
- }
- return _cancelBtn;
- }
- - (UIButton *)confirmBtn {
- if(!_confirmBtn){
- _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _confirmBtn.backgroundColor = self.confirmBgColor;
- _confirmBtn.titleLabel.font = self.confirmFont;
- [_confirmBtn setTitleColor:self.confirmTitleColor forState:UIControlStateNormal];
- [_confirmBtn setTitle:self.confirmTitle forState:UIControlStateNormal];
- _confirmBtn.layer.cornerRadius = self.confirmRadius;
- _confirmBtn.layer.borderWidth = self.confirmBorderWidth;
- _confirmBtn.layer.borderColor = self.confirmBorderColor.CGColor;
- WS(weakSelf)
- [[[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(YES,weakSelf.contentTextView.text);
- }
- }];
- }
- return _confirmBtn;
- }
- - (UIButton *)singleConfirmBtn {
- if(!_singleConfirmBtn){
- _singleConfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _singleConfirmBtn.backgroundColor = self.confirmBgColor;
- _singleConfirmBtn.titleLabel.font = self.confirmFont;
- [_singleConfirmBtn setTitleColor:self.confirmTitleColor forState:UIControlStateNormal];
- [_singleConfirmBtn setTitle:self.confirmTitle forState:UIControlStateNormal];
- _singleConfirmBtn.layer.cornerRadius = self.confirmRadius;
- _singleConfirmBtn.layer.borderWidth = self.confirmBorderWidth;
- _singleConfirmBtn.layer.borderColor = self.confirmBorderColor.CGColor;
- WS(weakSelf)
- [[[_singleConfirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if (weakSelf.buttonBlock) {
- weakSelf.buttonBlock(YES,weakSelf.contentTextView.text);
- }
- }];
- }
- return _singleConfirmBtn;
- }
- @end
|