|
@@ -17,6 +17,8 @@
|
|
|
|
|
|
@property (nonatomic, copy) GroupIntroduceModifyCallback callback;
|
|
|
|
|
|
+@property (nonatomic, assign) NSInteger maxInputCount;
|
|
|
+
|
|
|
|
|
|
@end
|
|
|
|
|
@@ -25,6 +27,13 @@
|
|
|
- (void)awakeFromNib {
|
|
|
[super awakeFromNib];
|
|
|
self.inputView.delegate = self;
|
|
|
+ self.inputView.textContainer.lineFragmentPadding = 0;
|
|
|
+ self.inputView.textContainerInset = UIEdgeInsetsZero;
|
|
|
+ [self configDefault];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)configDefault {
|
|
|
+ self.maxInputCount = 200;
|
|
|
}
|
|
|
|
|
|
+ (instancetype)sharedInstance {
|
|
@@ -41,7 +50,7 @@
|
|
|
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
|
|
|
paragraphStyle.lineSpacing = 4.0f;
|
|
|
- UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
|
|
|
+ UIFont *font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
|
|
|
if (![NSString isEmptyString:introduceString]) {
|
|
|
NSDictionary *attributes = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:HexRGB(0x333333)};
|
|
|
self.inputView.attributedText = [[NSAttributedString alloc] initWithString:introduceString attributes:attributes];
|
|
@@ -52,12 +61,95 @@
|
|
|
[self endEditing:YES];
|
|
|
if (self.callback) {
|
|
|
if ([NSString isEmptyString:self.inputView.text]) {
|
|
|
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入标题"];
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:self.tipsLabel.text];
|
|
|
return;
|
|
|
}
|
|
|
self.callback(self.inputView.text);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#pragma mark ---- delegate
|
|
|
+
|
|
|
+- (void)textViewDidBeginEditing:(UITextView *)textView {
|
|
|
+ self.tipsLabel.hidden = YES;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)textViewDidEndEditing:(UITextView *)textView {
|
|
|
+ if ([NSString isEmptyString:textView.text]) {
|
|
|
+ self.tipsLabel.hidden = NO;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
|
|
|
+ UITextRange *markedTextRange = textView.markedTextRange;
|
|
|
+ if (markedTextRange) {
|
|
|
+ // 当前处于拼音输入状态,暂不更新 attributedText
|
|
|
+ return YES;
|
|
|
+ }
|
|
|
+ NSInteger limitCount = self.maxInputCount;
|
|
|
+
|
|
|
+ NSString *newText = [[textView text] stringByReplacingCharactersInRange:range withString:text];
|
|
|
+ if (newText.length > limitCount) {
|
|
|
+ newText = [newText substringWithRange:NSMakeRange(0, limitCount)];
|
|
|
+ textView.text = newText;
|
|
|
+ }
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updateTextViewLineHeight:(UITextView *)textView {
|
|
|
+ UITextRange *markedTextRange = textView.markedTextRange;
|
|
|
+ if (markedTextRange) {
|
|
|
+ // 当前处于拼音输入状态,暂不更新 attributedText
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ [UIView setAnimationsEnabled:NO];
|
|
|
+ NSRange selectedRange = textView.selectedRange;
|
|
|
+ NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:textView.text attributes:[self getTypeAttributes]];
|
|
|
+ textView.attributedText = attrs;
|
|
|
+ textView.selectedRange = selectedRange;
|
|
|
+ [UIView setAnimationsEnabled:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)textViewDidChange:(UITextView *)textView {
|
|
|
+ // 获取当前高亮的部分(如果正在拼音输入状态)
|
|
|
+ UITextRange *selectedRange = [textView markedTextRange];
|
|
|
+ UITextPosition *position = [textView positionFromPosition:selectedRange.start offset:0];
|
|
|
+
|
|
|
+ // 如果没有高亮选择的文本,说明不是拼音输入状态
|
|
|
+ if (!position) {
|
|
|
+ // 获取当前textView的内容
|
|
|
+ NSInteger limitCount = self.maxInputCount;
|
|
|
+ NSString *currentText = textView.text;
|
|
|
+
|
|
|
+ // 如果文本超出最大长度,进行截取
|
|
|
+ if (currentText.length > limitCount) {
|
|
|
+ NSString *limitedText = [currentText substringToIndex:limitCount];
|
|
|
+ textView.text = limitedText;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.countLabel.text = [NSString stringWithFormat:@"%zd/%zd",textView.text.length,self.maxInputCount];
|
|
|
+ }
|
|
|
+ [self updateTextViewLineHeight:textView];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
|
|
|
+ [self endEditing:YES];
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
|
+ [self endEditing:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (NSDictionary *)getTypeAttributes {
|
|
|
+ NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
|
|
|
+ paragraphStyle.lineSpacing = 4.0f;
|
|
|
+ UIFont *font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
|
|
|
+
|
|
|
+ NSDictionary *attributes = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:HexRGB(0x333333)};
|
|
|
+ return attributes;
|
|
|
+}
|
|
|
/*
|
|
|
// Only override drawRect: if you perform custom drawing.
|
|
|
// An empty implementation adversely affects performance during animation.
|