class AKAttachement: NSTextAttachment{
var tag:Int!
var frame: CGRect!
var type: String!
var url: URL?
var completionHandler:((CGRect)->Void)?
func configure(type:String, tag:Int,frame:CGRect,_url:URL?) {
self.tag = tag
self.type = type
self.url = _url
self.frame = frame
}
override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect {
let superRect = super.attachmentBounds(for: textContainer, proposedLineFragment: lineFrag, glyphPosition: position, characterIndex: charIndex)
completionHandler?(lineFrag)
print(lineFrag)
return superRect
}
}
我将数据存储在属性中并将其附加到NSAttributedString
当我试图获取AKAttachment
子类的对象时NSTextAttachment
。
我能够得到对象。但是将type属性设置为 nil。