2017-11-24 7 views
0

enter image description heretextcolorは変更私は色付きのテキストタイピングのためのTextViewを使用しています

のTextView IOSの入力中。色やタイピングを選択する際に

、色は私がピリオド(。)、「こんにちは」、「HHH」の後に置かれた後、まだ赤であるかを確認期間

を配置するまで表示され続けるべき?だから私は、場所(。)後に色が黒に戻ってデフォルトする必要があることを言っている。

- (BOOL)growingTextView:(HPGrowingTextView *)growingTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 
{ 
if ([text isEqualToString:@"."]) { 
    txtMessage.textColor=[UIColor blackColor]; 
} 
} 

このコードはすべてのテキストを黒色にしました。

この機能をTextviewでどのように管理できますか?

答えて

0

あなたは私が..これが私の全体のTextViewの色が黒になることを試みているあなたのUITextview

func textViewDidChange(_ textView: UITextView) { //Handle the text changes here 
    if textView.text!.lowercased().range(of:".") { // Check your textview string has "." then set black color 
     // set black color 

     let splitStringArr = textView.text!.characters.split(separator: ".", maxSplits: 1) // split first match "." 

     if splitStringArr.count > 0 { 
      let redString = splitStringArr[0] 
      let blackString = splitStringArr[1] 
      if redString.count > 0 { 
       myMutableString1 = NSMutableAttributedString(string: redString, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!]) // set font as you like 
       myMutableString1.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range:NSRange(location:0,length:redString.count))     
      } 
      if blackString.count > 0 { 
       myMutableString2 = NSMutableAttributedString(string: redString, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!]) // set font as you like 
       myMutableString2.addAttribute(NSForegroundColorAttributeName, value: UIColor.blackColor(), range:NSRange(location:0,length:blackString.count)) 
      } 
      [mutableAttString1 appendAttributedString:newAttString2]; 
      labName.attributedText = myMutableString1 
     } 
     else { 
      // set red color 
     } 

    } 


} 
+0

textViewDidChange方法を追加する必要があります。私はちょうどドット(。)の後に黒い色をしたい –

+0

@ VarinderSinghのチェックが更新されました – iPatel

+0

あなたは自分で変換する必要があります。私はあなたにヒントを与えています – iPatel

関連する問題