【发布时间】:2020-06-17 11:17:02
【问题描述】:
嘿,我创建了一个 textview,我可以在这个 textview 中添加图像。这个图像的宽度等于 textview 的宽度。但我想为这个 ImageView 提供一个最大高度,我想显示图像,如内容模式缩放方面适合,但它显示拉伸(压缩方面填充)我该如何解决这种情况?如下代码
let image = UIImageView()
image.contentMode = .scaleAspectFit
let imageAttachment = NSTextAttachment()
let newImageWidth = self.textView.bounds.width
let newImageHeight = 200
imageAttachment.bounds = CGRect(x: 0, y: 0, width: Int(newImageWidth), height: newImageHeight)
imageAttachment.image = image.image
【问题讨论】:
标签: swift uiimageview uitextview aspect-ratio nstextattachment