I have an UITextView for entering the comments for the photos. When the user enters their text in UITextView the entered last text should be in Dark gray color other texts should be in normal color. Once the user entered Space the last entered word/text should change to black(normal) color.
UITextView text eg: iPhone is an apple product. Product should be in Dark gray color others in black color. Once user enter space the all entire words in black color.
How can i detect the last entered word and how can i change the particular last entered word text color?
EDITED :
I am trying this source code.
-(void) textViewDidChange:(UITextView *)textView
{
NSArray *lastTextArray = [textView.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
lastStringInTextView = [lastTextArray objectAtIndex:lastTextArray.count - 1];
NSLog(@"LastText : %@", lastStringInTopTextView);
textView.textColor = [UIColor orangeColor];
}
I think you need to define a listener(from the text field you entered) and it will look for a white space character(mean ' '
) in your text enter. The text color&type can be somethink like yourTextField.font=[UIFont boldSystemFontOfSize:24]
untill the listener detects a space, and when it detects the space must change to normal(and the new string must get started be typed as yourTextField.font=[UIFont boldSystemFontOfSize:24]
...)
Note: This is may be not a true aproach to start answering with I think.. but you have asked for any idea. I hope this helps
EDIT: This needs a good algorithm, also using blocks in the same method which will do this work. The algorithm must be designed in order to accept any ' '
character as the beginning of text field.