114 lines
4.3 KiB
Mathematica
114 lines
4.3 KiB
Mathematica
|
|
//
|
||
|
|
// QXDynamicCommentInputView.m
|
||
|
|
// QXLive
|
||
|
|
//
|
||
|
|
// Created by 启星 on 2025/6/4.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import "QXDynamicCommentInputView.h"
|
||
|
|
|
||
|
|
@interface QXDynamicCommentInputView()<UITextFieldDelegate>
|
||
|
|
@property (nonatomic,strong)UICollectionView *collectionViwew;
|
||
|
|
@property (nonatomic,strong)UIView *inputBgView;
|
||
|
|
@property (nonatomic,strong)UIView *inputShadowView;
|
||
|
|
|
||
|
|
@property (nonatomic,strong)UIButton *sendBtn;
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation QXDynamicCommentInputView
|
||
|
|
|
||
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
|
{
|
||
|
|
self = [super initWithFrame:frame];
|
||
|
|
if (self) {
|
||
|
|
[self initSubviews];
|
||
|
|
}
|
||
|
|
return self;
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)initSubviews{
|
||
|
|
self.backgroundColor = [UIColor whiteColor];
|
||
|
|
|
||
|
|
self.sendBtn = [[UIButton alloc] init];
|
||
|
|
self.sendBtn.needEventInterval = 0.5;
|
||
|
|
[self.sendBtn setTitle:QXText(@"发送") forState:(UIControlStateNormal)];
|
||
|
|
self.sendBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||
|
|
[self.sendBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)];
|
||
|
|
self.sendBtn.backgroundColor = QXConfig.themeColor;
|
||
|
|
[self.sendBtn addRoundedCornersWithRadius:17.5];
|
||
|
|
[self.sendBtn addTarget:self action:@selector(sendAction) forControlEvents:(UIControlEventTouchUpInside)];;
|
||
|
|
[self addSubview:self.sendBtn];
|
||
|
|
[self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.right.mas_equalTo(-16);
|
||
|
|
make.top.mas_equalTo(8);
|
||
|
|
make.height.mas_equalTo(35);
|
||
|
|
make.width.mas_equalTo(80);
|
||
|
|
}];
|
||
|
|
|
||
|
|
|
||
|
|
self.inputBgView = [[UIView alloc] init];
|
||
|
|
self.inputBgView.backgroundColor = RGB16(0xF5F5F5);
|
||
|
|
[self.inputBgView addRoundedCornersWithRadius:8];
|
||
|
|
[self addSubview:self.inputBgView];
|
||
|
|
[self.inputBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.left.mas_equalTo(16);
|
||
|
|
make.right.equalTo(self.sendBtn.mas_left).offset(-12);
|
||
|
|
make.centerY.equalTo(self.sendBtn);
|
||
|
|
make.height.mas_equalTo(35);
|
||
|
|
}];
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
self.textField = [[UITextField alloc] init];
|
||
|
|
self.textField.font = [UIFont systemFontOfSize:14];
|
||
|
|
self.textField.textColor = QXConfig.textColor;
|
||
|
|
self.textField.returnKeyType = UIReturnKeyDone;
|
||
|
|
self.textField.delegate = self;
|
||
|
|
[self.textField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
|
||
|
|
[self.inputBgView addSubview:self.textField];
|
||
|
|
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
|
make.left.mas_equalTo(10);
|
||
|
|
make.right.mas_equalTo(-10);
|
||
|
|
make.top.bottom.equalTo(self.inputBgView);
|
||
|
|
}];
|
||
|
|
|
||
|
|
self.inputShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 4)];
|
||
|
|
self.inputShadowView.backgroundColor = [UIColor whiteColor];
|
||
|
|
self.inputShadowView.layer.shadowColor = [UIColor grayColor].CGColor;
|
||
|
|
self.inputShadowView.layer.shadowOpacity = 0.2;
|
||
|
|
self.inputShadowView.layer.shadowOffset = CGSizeMake(0, -2);
|
||
|
|
self.inputShadowView.layer.shadowRadius = 2;
|
||
|
|
self.inputShadowView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.inputShadowView.bounds cornerRadius:self.inputShadowView.layer.cornerRadius].CGPath;
|
||
|
|
self.inputShadowView.layer.cornerRadius = 2;
|
||
|
|
self.inputShadowView.layer.masksToBounds = NO;
|
||
|
|
[self addSubview:self.inputShadowView];
|
||
|
|
// self.inputShadowView.layer.shadowColor = [UIColor grayColor].CGColor;
|
||
|
|
// self.inputShadowView.layer.shadowOpacity = 0.5;
|
||
|
|
// self.inputShadowView.layer.shadowOffset = CGSizeMake(0, -2);
|
||
|
|
//// self.inputShadowView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:0].CGPath;
|
||
|
|
// self.inputShadowView.layer.masksToBounds = NO;
|
||
|
|
}
|
||
|
|
-(void)textDidChange:(UITextField*)textField{
|
||
|
|
if (textField.text.length>50) {
|
||
|
|
showToast(@"评论不得超过50个字符");
|
||
|
|
textField.text = [textField.text substringToIndex:50];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
||
|
|
[textField resignFirstResponder];
|
||
|
|
return YES;
|
||
|
|
}
|
||
|
|
-(void)setModel:(QXDynamicCommentListModel *)model{
|
||
|
|
_model = model;
|
||
|
|
}
|
||
|
|
-(void)inputBecomeFirstResponder{
|
||
|
|
[self.textField becomeFirstResponder];
|
||
|
|
}
|
||
|
|
|
||
|
|
-(void)sendAction{
|
||
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickSendWithText:model:)]) {
|
||
|
|
[self.delegate didClickSendWithText:self.textField.text model:self.model];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
@end
|