Browse Source

公告内容输入textview设置行高

Steven 2 days ago
parent
commit
12f6ed110a

+ 1 - 6
KulexiuForTeacher/KulexiuForTeacher/Module/Chat/GroupNotice/Controller/GroupNoticeEditController.m

@@ -37,12 +37,7 @@
         [weakSelf submitAction];
     }];
     if (_isModify) {
-        self.bodyView.titleView.text = [NSString returnNoNullStringWithString:self.titles];
-        self.bodyView.titleCount.text = [NSString stringWithFormat:@"%zd/25",self.titles.length];
-        self.bodyView.contentArea.text = [NSString returnNoNullStringWithString:self.content];
-        self.bodyView.contentCount.text = [NSString stringWithFormat:@"%zd/200",self.content.length];
-       self.bodyView.topTipsLabel.hidden = [NSString isEmptyString:self.titles] ? NO : YES;
-        self.bodyView.tipsLabel.hidden = [NSString isEmptyString:self.content] ? NO : YES;
+        [self.bodyView configTitle:self.titles content:self.content];
         self.bodyView.isOn = self.isOn;
     }
     else {

+ 2 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Chat/GroupNotice/View/NoticeEditBodyView.h

@@ -27,6 +27,8 @@ typedef void(^PublishBlock)(void);
 
 + (instancetype)shareInstance;
 
+- (void)configTitle:(NSString *)title content:(NSString *)content;
+
 - (void)publishCallback:(PublishBlock)callback;
 
 @end

+ 36 - 0
KulexiuForTeacher/KulexiuForTeacher/Module/Chat/GroupNotice/View/NoticeEditBodyView.m

@@ -30,6 +30,27 @@
     return view;
 }
 
+- (void)configTitle:(NSString *)title content:(NSString *)content {
+    self.titleCount.text = [NSString stringWithFormat:@"%zd/25",title.length];
+    self.contentCount.text = [NSString stringWithFormat:@"%zd/200",content.length];
+    
+    self.topTipsLabel.hidden = [NSString isEmptyString:title] ? NO : YES;
+    self.tipsLabel.hidden = [NSString isEmptyString:content] ? NO : YES;
+    
+    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
+    paragraphStyle.lineSpacing = 4.0f;
+    UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
+    if (![NSString isEmptyString:title]) {
+        NSDictionary *attributes = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:HexRGB(0x333333)};
+        self.titleView.attributedText = [[NSAttributedString alloc] initWithString:title attributes:attributes];
+    }
+    
+    if (![NSString isEmptyString:content]) {
+        NSDictionary *attributes = @{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:HexRGB(0x333333)};
+        self.contentArea.attributedText = [[NSAttributedString alloc] initWithString:content attributes:attributes];
+    }
+}
+
 - (void)publishCallback:(PublishBlock)callback {
     if (callback) {
         self.callback = callback;
@@ -106,6 +127,21 @@
     return YES;
 }
 
+- (void)updateTextViewLineHeight:(UITextView *)textView {
+    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
+    paragraphStyle.lineSpacing = 4.0f;
+    UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
+    [UIView setAnimationsEnabled:NO];
+    NSRange selectedRange = textView.selectedRange;
+    NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:textView.text attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:font, NSForegroundColorAttributeName:HexRGB(0x333333)}];
+    textView.attributedText = attrs;
+    textView.selectedRange = selectedRange;
+    [UIView setAnimationsEnabled:YES];
+}
+
+- (void)textViewDidChange:(UITextView *)textView {
+    [self updateTextViewLineHeight:textView];
+}
 
 - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
     [self endEditing:YES];