Ios NSTextAttachment使textview字体的大小变小

Ios NSTextAttachment使textview字体的大小变小,ios,swift,uitextview,Ios,Swift,Uitextview,我在文本视图中得到了一个属性字符串,图像显示良好。但是,当我将图像添加到textview时,textview的原始字体会变小。我想字体保持不变后,图像被添加。我不知道这是什么原因,任何帮助都将不胜感激 这就是我迄今为止所尝试的: var mutableAttrString = NSMutableAttributedString() let attachment = NSTextAttachment() attachment.image = selectedImage l

我在文本视图中得到了一个属性字符串,图像显示良好。但是,当我将图像添加到textview时,textview的原始字体会变小。我想字体保持不变后,图像被添加。我不知道这是什么原因,任何帮助都将不胜感激

这就是我迄今为止所尝试的:

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
之后

以前

这是一种可能的解决方案