在ios中添加\ n到带有属性字符串的uitextview

时间:2015-07-22 05:09:16

标签: ios objective-c iphone

我有一个问题是将\ n添加到带有属性字符串的uitextview中,我使用自定义表情符号将其添加到uitextview中,以便我正在使用此

 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]init];

attributedString = [_txtView.attributedText mutableCopy];

NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
NSString *strName = [NSString stringWithFormat:@"%@",[[_arrEmojis objectAtIndex:indexPath.row] valueForKey:@"image"]];

textAttachment.image = [UIImage imageNamed:strName];

textAttachment.bounds = CGRectMake(0, -12, 44, 44);

NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];

[attributedString insertAttributedString:attrStringWithImage atIndex:_txtView.selectedRange.location];

_txtView.attributedText = attributedString;

NSLog(@"%d",_txtView.attributedText.length);

_txtView.font = [UIFont fontWithName:FontName size:FontSize];

在uitextview中添加了表情符号,但是当我使用此代码添加\ n时,textview的光标保持在同一级别,当我重新添加任何自定义表情符号时,它会在正确的末尾添加,但不会自动向上滚动。

如果有人遇到同样的问题,请回复。

0 个答案:

没有答案