| let attachment = NSTextAttachment()
 
 attachment.image = UIImage(contentsOfFile: emoticon.imagePath!)
 
 attachment.bounds = CGRect(x: 0, y: -4, width: 20, height: 20)
 
 let imageText = NSAttributedString(attachment: attachment)
 
 let strM = NSMutableAttributedString(attributedString: self.textView.attributedText)
 
 let range = self.textView.selectedRange
 strM.replaceCharactersInRange(range,withAttributedString: imageText)
 
 strM.addAttribute(NSFontAttributeName,value: UIFont.systemFontOfSize(19),range: NSMakeRange(range.location, 1))
 
 self.textView.attributedText = strM
 
 self.textView.selectedRange = NSMakeRange(range.location  + 1, 0)
 
 |