如何更改UITextView在iPhone中最后输入的文本颜色? [英] How to change UITextView last entered text color in iPhone?

查看:58
本文介绍了如何更改UITextView在iPhone中最后输入的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITextView用于输入照片的注释.当用户在UITextView中输入其文本时,最后输入的文本应为深灰色,其他文本应为常规颜色.一旦用户输入了空格,最后输入的单词/文本应更改为黑色(正常)颜色.

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?

我正在尝试此源代码.

-(void) textViewDidChange:(UITextView *)textView
{
   NSArray *lastTextArray = [textView.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

   lastStringInTextView = [lastTextArray objectAtIndex:lastTextArray.count - 1];
   NSLog(@"LastText : %@", lastStringInTopTextView);

   textView.textColor = [UIColor orangeColor];
}

推荐答案

我认为您需要定义一个侦听器(从您输入的文本字段开始),它将寻找空白字符(表示'')中输入.文本的颜色和类型可以像 yourTextField.font = [UIFont boldSystemFontOfSize:24] 这样,直到侦听器检测到空格,并且当它检测到空格必须更改为正常(并且新字符串必须开始键入为 yourTextField.font = [UIFont boldSystemFontOfSize:24] ...)注意:这不是开始以我认为.回答的真正方法,但是您已要求任何想法.希望对您有帮助

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

编辑:这需要一个好的算法,也要使用相同的方法来完成这项工作.必须设计算法,以便接受任何''字符作为文本字段的开头.

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.

这篇关于如何更改UITextView在iPhone中最后输入的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆