Ios UITextView属性文本中的垂直文本
我有一个UITextView,用户在其中输入文本。我添加了一些代码,这样当输入的文本包含一个#hashtag时,该单词将被涂成蓝色。代码如下:Ios UITextView属性文本中的垂直文本,ios,text,uitextview,nsattributedstring,vertical-text,Ios,Text,Uitextview,Nsattributedstring,Vertical Text,我有一个UITextView,用户在其中输入文本。我添加了一些代码,这样当输入的文本包含一个#hashtag时,该单词将被涂成蓝色。代码如下: - (void)textViewDidChange:(UITextView *)textView { //Coloring of hashtags NSArray *words = [textView.text componentsSeparatedByString:@" "]; NSMutableAttributedStrin
- (void)textViewDidChange:(UITextView *)textView
{
//Coloring of hashtags
NSArray *words = [textView.text componentsSeparatedByString:@" "];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:textView.text];
for (NSString *word in words)
{
if ([word hasPrefix:@"#"])
{
NSRange matchRange = [textView.text rangeOfString:word];
[attrString addAttribute:NSForegroundColorAttributeName value:[AppereanceConfiguration defaultTintColor] range:matchRange];
}
}
textView.attributedText = attrString;
}
在iOS7上工作正常,但在iOS6上,只要我开始键入文本,文本就开始垂直向下。例如:如果我想输入单词“Test”-当我按“T”时,它看起来很好,但当我按“e”时,它会在新行中的“T”下方显示,以此类推。下一个字母出现在上一个字母下面
如何修复此问题?尝试以下方法:
- (void)textViewDidChange:(UITextView *)textView {
[textView setTypingAttributes:{@NSForegroundColorAttributeName:[AppereanceConfiguration defaultTintColor]}];
}
添加条件,无需每次创建NSMutableAttributeString