ios UITextView在带有中文输入的标记文本中重复显示NSTEXT附件。[ios7 5c]

ios UITextView在带有中文输入的标记文本中重复显示NSTEXT附件。[ios7 5c],ios,uitextview,nstextattachment,Ios,Uitextview,Nstextattachment,我想使用NSTextAttachment将“文本图像”插入文本视图。如果文本是英文,这没关系,但是如果文本是中文,就有问题了。守则: - (IBAction)insertAt:(id)sender { UIColor *color = [UIColor redColor]; UIFont *font = [UIFont systemFontOfSize:18.0]; NSTextAttachment *at = [[NSTextAttachment alloc] init]; NSStrin

我想使用
NSTextAttachment
将“文本图像”插入文本视图。如果文本是英文,这没关系,但是如果文本是中文,就有问题了。守则:

- (IBAction)insertAt:(id)sender {
UIColor *color = [UIColor redColor];
UIFont *font = [UIFont systemFontOfSize:18.0];


NSTextAttachment *at = [[NSTextAttachment alloc] init];
NSString *name = @"TEST";
at.image = [self getImage:name];

NSMutableAttributedString *atAttribuString = [[NSAttributedString attributedStringWithAttachment:at] mutableCopy];
[atAttribuString addAttributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:color} range:NSMakeRange(0, atAttribuString.length)];

[self.textView.textStorage replaceCharactersInRange:self.textView.selectedRange
                               withAttributedString:atAttribuString];

self.textView.markedTextStyle = @{NSFontAttributeName:font, NSForegroundColorAttributeName:color};
}

}


在中文输入中,插入NSTEXTATTACHINE后,无论我输入什么,NSTEXTATTACHINE只需在标记区域插入重复显示即可。。但是,当我用ios8maybe进行测试时,应该重置textViewStyle或其他东西,这是正常的,因为在插入附件之后,我键入一个空格,然后每个都可以。
- (UIImage*)getImage:(NSString*)text {
UIColor *color = [UIColor redColor];
UIFont *font = [UIFont systemFontOfSize:18.0];

CGRect rect = [text boundingRectWithSize:CGSizeMake(1000, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:color} context:nil];
CGFloat leading = 0.0;
rect = CGRectMake(leading, 0.0, CGRectGetWidth(rect) + leading * 2, CGRectGetHeight(rect));

//    UIGraphicsBeginImageContext(rect.size);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);
[text drawInRect:rect withAttributes:@{NSFontAttributeName:font, NSForegroundColorAttributeName:color}];
// 从当前context中创建一个改变大小后的图片
UIImage *textImage = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
return textImage;