Files
keyboard/keyBoard/Class/Me/VC/KBFeedBackVC.m

165 lines
5.8 KiB
Mathematica
Raw Normal View History

2025-11-24 20:15:41 +08:00
#import "KBFeedBackVC.h"
#import <Masonry/Masonry.h>
@interface KBFeedBackVC () <UITextViewDelegate>
///
@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<UITouch *> *)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 = [UIFont systemFontOfSize:16];
_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 = [UIFont systemFontOfSize:16];
_placeholderLabel.text = KBLocalized(@"Please Enter The Content");
}
return _placeholderLabel;
}
- (UILabel *)countLabel {
if (!_countLabel) {
_countLabel = [UILabel new];
_countLabel.textColor = [UIColor colorWithWhite:0.7 alpha:1.0];
_countLabel.font = [UIFont systemFontOfSize:14];
_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 = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
// 使
_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