Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITextView属性文本中的垂直文本_Ios_Text_Uitextview_Nsattributedstring_Vertical Text - Fatal编程技术网

Ios UITextView属性文本中的垂直文本

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

我有一个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”下方显示,以此类推。下一个字母出现在上一个字母下面

如何修复此问题?

尝试以下方法:

- (void)textViewDidChange:(UITextView *)textView {

[textView setTypingAttributes:{@NSForegroundColorAttributeName:[AppereanceConfiguration defaultTintColor]}];
}
添加条件,无需每次创建NSMutableAttributeString