2017-11-24 1 views
0

enter image description here텍스트 색상 변화 나 컬러 텍스트 입력을위한 텍스트 뷰를 사용하고

텍스트 뷰 IOS에 입력하는 동안. 색상 및 입력을 선택할 때

, 색상은 내가 마침표 (.) "안녕하세요"는 "HHH"다음에 배치 후에도 레드하는 방법을 알아보십시오 기간

을 배치 할 때까지 계속 표시해야합니까? 그래서 나는 말하기를 마침표 뒤에 마침표 (.) 색은 검은 색으로 되돌아 와야합니다.

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

이 코드는 모든 텍스트를 검은 색으로 표시했습니다.

어떻게이 기능을 Textview에서 관리 할 수 ​​있습니까?

답변

0

당신은 내가 ..이 내 전체 텍스트 뷰 컬러 블랙을 만드는 것을 시도하여 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