【发布时间】:2013-12-13 13:52:45
【问题描述】:
我有一个 UITextView,用户可以在其中输入文本。我添加了一些代码,以便当输入的文本包含#hashtag 时,该词将显示为蓝色。代码如下:
- (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”下面,依此类推。下一个字母出现在前一个字母的下方。
我该如何解决这个问题?
【问题讨论】:
标签: ios text uitextview nsattributedstring vertical-text