I am adding images to compose bar’s textview using NSTextAttachment. But when I add more than 2-3 images, textview is not exactly scrolling to caret. Also when I have a combination of text and images (image at last) and when I tap on last line of compose bar, it does not scroll to last line, it scrolls on first or second line or image. Please check my code :
let attachment = ChatTextAttachment()
attachment.image = thumbImage
// Add NSTextAttachment into attributedString
let attributedString = NSMutableAttributedString(string: "", attributes: [NSFontAttributeName:UIFont.systemFontOfSize(14)])
let attrStringWithImage = NSAttributedString(attachment: attachment)
attributedString.appendAttributedString(attrStringWithImage)
attributedString.appendAttributedString(NSAttributedString(string: "\n", attributes: [NSFontAttributeName:UIFont.systemFontOfSize(14)]))
// Add this attributed string to the current position.
self.composeBar.textView.textStorage.insertAttributedString(attributedString, atIndex: self.composeBar.textView.selectedRange.location)
self.composeBar.textView.select(self)
self.composeBar.textView.selectedRange = NSMakeRange(self.composeBar.textView.attributedText.length, 0 );
self.textViewDidChange(self.composeBar.textView)
self.composeBar.textView.layoutIfNeeded()
ChatTextAttachment is a subclass of NSTextAttachment
Let me know if you need any more details.
I am adding images to compose bar’s textview using NSTextAttachment. But when I add more than 2-3 images, textview is not exactly scrolling to caret. Also when I have a combination of text and images (image at last) and when I tap on last line of compose bar, it does not scroll to last line, it scrolls on first or second line or image. Please check my code :
ChatTextAttachment is a subclass of NSTextAttachment Let me know if you need any more details.