Attachment
open class Attachment : NSTextAttachment, BoundsObserving
An attachment can be used as a container for any view object. Based on the AttachmentSize provided, the attachment automatically renders itself alongside the text in EditorView.
Attachment also provides helper functions like deleteFromContainer and rangeInContainer
-
Identifier that uniquely identifies an attachment. Auto-generated.
Declaration
Swift
public let id: String -
Governs if the attachment should be selected before being deleted. When
true, tapping the backspace key the first time on range containingAttachmentwill only select the attachment i.e. show as highlighted. Tapping the backspace again will delete the attachment. If the value isfalse, the attachment will be deleted on the first backspace itself.Declaration
Swift
public var selectBeforeDelete: Bool -
Estimated height for attachment when it is rendering asynchronously. This will result in a blank placeholder with given height for the attachment to render. When rendering completed, the Editor content will readjust to accomodate the actual height of
AttachmentDeclaration
Swift
public var estimatedHeight: CGFloat -
Undocumented
Declaration
Swift
public var needsDeferredRendering: Bool { get } -
Determines if attachment should be selected on tap or not. Defaults to
false.Note
Selection only takes place if the view in attachment does not handle touch i.e. if a button in AttachmentView is tapped,selectOnTapwill not work as the tap will be handled by the button.Declaration
Swift
public var selectOnTap: Bool -
Determines the appearance for the selection rectangle of the attachment
Declaration
Swift
public var selectionStyle: AttachmentSelectionStyle { get set } -
Undocumented
Declaration
Swift
public var isBlockType: Bool { get } -
Undocumented
Declaration
Swift
public var isInlineType: Bool { get } -
Attributed string representation of the
Attachment. This can be used directly to replace a range of text inEditorViewUsage Example
let attachment = Attachment(PanelView(), size: .fullWidth) let attrString = NSMutableAttributedString(string: "This is a test string") attrString.append(attachment.string) editor.attributedText = attrStringDeclaration
Swift
public var string: NSAttributedString { get } -
Name of the content contained within the
AttachmentDeclaration
Swift
public var name: EditorContent.Name? { get } -
Undocumented
Declaration
Swift
public var contentEditors: [EditorView] { get } -
Determines if Attachment is rendering async but is not yet rendered
Declaration
Swift
public var isPendingAsyncRendering: Bool { get } -
Determines if attachment is in selected range in the container
EditorViewDeclaration
Swift
public var isInSelectedRange: Bool { get } -
Undocumented
Declaration
Swift
public var contentSize: CGSize? { get } -
Attachment’s frame in ints container
EditorView. The value may be nil if attachment is not rendered yet.Declaration
Swift
public var frameInContainer: CGRect? { get } -
EditorViewcontaining this attachmentDeclaration
Swift
public private(set) weak var containerEditorView: EditorView? { get } -
Offsets for the attachment. Can be used to align attachment with the text. Defaults to
.zeroDeclaration
Swift
public weak var offsetProvider: AttachmentOffsetProviding? -
Name of the content for the
EditorViewSee also
EditorViewDeclaration
Swift
public var containerContentName: EditorContent.Name? { get } -
Undocumented
Declaration
Swift
public private(set) var contentView: UIView? { get set } -
Bounds of the container
Declaration
Swift
public var containerBounds: CGRect? { get } -
The bounds rectangle, which describes the attachment’s location and size in its own coordinate system.
Declaration
Swift
public override var bounds: CGRect { get set } -
Initializes an attachment with the image provided.
Note
Image and Size can be updated by invokingupdateImage(image: size:)at any timeDeclaration
Swift
public init(image: AttachmentImage)Parameters
imageImage to be used to display in the attachment. Image is rendered as Inline content.
-
Initializes the attachment with the given content view
Declaration
Swift
public init(_ contentView: AttachmentView, size: AttachmentSize, backgroundColor: UIColor? = nil)Parameters
contentViewContent view to be hosted within the attachment
sizeSize rule for attachment
backgroundColorBackground color of attachment. Can be used with DEBUG to track the attachment size/location with respect to content view
-
Selects the attachment in Editor.
Declaration
Swift
public func setSelected(_ isSelected: Bool)Parameters
isSelectedtrueto set selected, elsefalse -
Causes invalidation of layout of the attachment when the containing view bounds are changed
See also
BoundsObservingDeclaration
Swift
public func didChangeBounds(_ bounds: CGRect, oldBounds: CGRect)Parameters
boundsUpdated bounds
-
Removes this attachment from the
EditorViewit is contained in.Declaration
Swift
public func removeFromContainer() -
Range of this attachment in it’s container
Declaration
Swift
public func rangeInContainer() -> NSRange? -
Invoked when attributes are added in the containing
EditorViewin the range of string in which this attachment is contained.Declaration
Swift
open func addedAttributesOnContainingRange(rangeInContainer range: NSRange, attributes: [NSAttributedString.Key : Any])Parameters
rangeAffected range
attributesAttributes applied
-
Declaration
Swift
open func removedAttributesFromContainingRange(rangeInContainer range: NSRange, attributes: [NSAttributedString.Key])Parameters
rangeAffected range
attributesAttributes removed
-
Returns the calculated bounds for the attachment based on size rule and content view provided during initialization.
Declaration
Swift
public override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRectParameters
textContainerText container for attachment
lineFragLine fragment containing the attachment
positionPosition in the text container.
charIndexCharacter index
-
Undocumented
Declaration
Swift
public func update(with image: AttachmentImage) -
Undocumented
Declaration
Swift
public func update(_ contentView: AttachmentView, size: AttachmentSize) -
Undocumented
Declaration
Swift
open func getFullTextRangeIdentificationAttributes() -> [NSAttributedString.Key : Any] -
Invalidates the current layout and triggers a layout update.
Declaration
Swift
public func invalidateLayout()
View on GitHub
Attachment Class Reference