#import "KBFeedBackVC.h" #import @interface KBFeedBackVC () /// 输入卡片容器视图 @property (nonatomic, strong) UIView *inputCardView; /// 文本输入框 @property (nonatomic, strong) UITextView *textView; /// 占位提示标签:“Please Enter The Content” @property (nonatomic, strong) UILabel *placeholderLabel; /// 右下角字数统计 “0/100” @property (nonatomic, strong) UILabel *countLabel; /// 底部提交按钮 @property (nonatomic, strong) UIButton *commitButton; /// 最大输入字数 @property (nonatomic, assign) NSInteger maxCount; @end @implementation KBFeedBackVC - (void)viewDidLoad { [super viewDidLoad]; // 背景色与其他设置页一致 self.view.backgroundColor = [UIColor colorWithWhite:0.97 alpha:1.0]; self.kb_titleLabel.text = KBLocalized(@"Feedback"); self.maxCount = 100; // 添加子视图 [self.view addSubview:self.inputCardView]; [self.inputCardView addSubview:self.textView]; [self.inputCardView addSubview:self.placeholderLabel]; [self.inputCardView addSubview:self.countLabel]; [self.view addSubview:self.commitButton]; // 输入卡片布局 [self.inputCardView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(KB_NAV_TOTAL_HEIGHT + 16); make.left.equalTo(self.view).offset(16); make.right.equalTo(self.view).offset(-16); make.height.mas_equalTo(220); }]; // 文本输入框布局 [self.textView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.inputCardView).offset(16); make.left.equalTo(self.inputCardView).offset(16); make.right.equalTo(self.inputCardView).offset(-16); make.bottom.equalTo(self.inputCardView).offset(-32); }]; // 占位文字布局(叠在 textView 左上) [self.placeholderLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.textView).offset(2); make.left.equalTo(self.textView).offset(4); }]; // 字数统计布局(卡片右下角) [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.inputCardView).offset(-16); make.bottom.equalTo(self.inputCardView).offset(-10); }]; // 底部提交按钮布局 [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(24); make.right.equalTo(self.view).offset(-24); make.bottom.equalTo(self.view).offset(-KB_SAFE_BOTTOM - 24); make.height.mas_equalTo(56); }]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:true]; } #pragma mark - Actions /// 提交按钮点击(后续在此方法内实现具体提交逻辑) - (void)onTapCommit { NSString *content = self.textView.text ?: @""; // TODO: 在这里处理提交逻辑,例如校验 + 上报接口等 } #pragma mark - UITextViewDelegate // 文本变化时更新占位和字数 - (void)textViewDidChange:(UITextView *)textView { // 超出最大字数时截断 if (textView.text.length > self.maxCount) { textView.text = [textView.text substringToIndex:self.maxCount]; } self.placeholderLabel.hidden = textView.text.length > 0; self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld", (long)textView.text.length, (long)self.maxCount]; } #pragma mark - Lazy Load - (UIView *)inputCardView { if (!_inputCardView) { _inputCardView = [UIView new]; _inputCardView.backgroundColor = [UIColor whiteColor]; _inputCardView.layer.cornerRadius = 16.0; _inputCardView.layer.masksToBounds = YES; } return _inputCardView; } - (UITextView *)textView { if (!_textView) { _textView = [[UITextView alloc] init]; _textView.delegate = self; _textView.backgroundColor = [UIColor clearColor]; _textView.font = [KBFont medium:14]; _textView.textColor = [UIColor blackColor]; _textView.textContainerInset = UIEdgeInsetsZero; _textView.textContainer.lineFragmentPadding = 0; _textView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; } return _textView; } - (UILabel *)placeholderLabel { if (!_placeholderLabel) { _placeholderLabel = [UILabel new]; _placeholderLabel.textColor = [UIColor colorWithWhite:0.75 alpha:1.0]; _placeholderLabel.font = [KBFont medium:14]; _placeholderLabel.text = KBLocalized(@"Please Enter The Content"); } return _placeholderLabel; } - (UILabel *)countLabel { if (!_countLabel) { _countLabel = [UILabel new]; _countLabel.textColor = [UIColor colorWithHex:0xACACAC]; _countLabel.font = [KBFont regular:13]; _countLabel.textAlignment = NSTextAlignmentRight; _countLabel.text = @"0/100"; } return _countLabel; } - (UIButton *)commitButton { if (!_commitButton) { _commitButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_commitButton setTitle:KBLocalized(@"Commit") forState:UIControlStateNormal]; [_commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; _commitButton.titleLabel.font = [KBFont medium:16]; // 使用与修改昵称弹窗相近的主色 _commitButton.backgroundColor = [UIColor colorWithRed:0.02 green:0.75 blue:0.67 alpha:1.0]; _commitButton.layer.cornerRadius = 28.0; _commitButton.layer.masksToBounds = YES; // 胶囊按钮 [_commitButton addTarget:self action:@selector(onTapCommit) forControlEvents:UIControlEventTouchUpInside]; } return _commitButton; } @end