我UITextView
用给定的属性描述如下:
lazy var inputTextView: UITextView = {
let tv = UITextView()
tv.backgroundColor = .white
tv.textContainerInset = UIEdgeInsetsMake(12, 12, 12, 12) // Posicionamento do texto
let spacing = NSMutableParagraphStyle()
spacing.lineSpacing = 4
let attr = [NSParagraphStyleAttributeName : spacing, NSFontAttributeName: UIFont.systemFont(ofSize: 16), NSForegroundColorAttributeName: UIColor.blue]
tv.typingAttributes = attr
return tv
}()
在我将图像附加到UITextView
.
图像被插入到所需的位置,但在插入后它会覆盖我的textView
属性。
文本变小,颜色与我在其声明中实现的属性不同。
我附上图片如下:
let att = NSTextAttachment()
att.image = image
let attrString = NSAttributedString(attachment: att)
self.inputTextView.textStorage.insert(attrString, at: self.currentCursorLocation)
是什么导致了这个问题?
每当我UIImage
在其内容中插入一个时,我什至尝试增强其属性。
添加图像时,我尝试了以下操作:
let att = NSTextAttachment()
att.image = image
let attrString = NSAttributedString(attachment: att)
self.inputTextView.textStorage.insert(attrString, at: self.currentCursorLocation)
let spacing = NSMutableParagraphStyle()
spacing.lineSpacing = 4
let attr = [NSParagraphStyleAttributeName : spacing, NSFontAttributeName: UIFont.systemFont(ofSize: 16), NSForegroundColorAttributeName: UIColor.blue]
self.inputTextView.typingAttributes = attr
而且它仍然没有改变它的属性。
是什么导致了这个问题?任何提示?
谢谢
编辑
正如这里所建议的那样,这是我设置光标位置的方式
func textViewDidChange(_ textView: UITextView) {
currentCursorLocation = textView.selectedRange.location
}
我这样做是为了在文本闪烁光标的当前位置插入图像