2

I got an attributed string inside a textview, the image is displaying fine. However, when i add the image to the textview the original font of the textview gets smaller. I would like the fonts to stay the same after the image is added. I dont what is causing this, any help would appreciated.

This is what I've tried so far:

var mutableAttrString = NSMutableAttributedString()

    let attachment = NSTextAttachment()
    attachment.image = selectedImage
    let newImageWidth = (textView.bounds.size.width - 10 )
    let scale = newImageWidth/(selectedImage.size.width)
    let newImageHeight = selectedImage.size.height * scale
    attachment.bounds = CGRect(x: 0, y: 0, width: newImageWidth, height: newImageHeight)
    let myAttributedString = NSAttributedString(attachment: attachment)
    let text:[String:Any] = [NSFontAttributeName:UIFont.boldSystemFont(ofSize: 20)]
    let textAttr = NSMutableAttributedString(string: "bottom of image \n", attributes: text)

    mutableAttrString.append(myAttributedString)
    mutableAttrString.append(textAttr)

    textView.attributedText = mutableAttrString

After After image is added

Before enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Iam Wayne
  • 561
  • 6
  • 26

0 Answers0