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 containingAttachment
will 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
Attachment
Declaration
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,selectOnTap
will 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 inEditorView
Usage Example
let attachment = Attachment(PanelView(), size: .fullWidth) let attrString = NSMutableAttributedString(string: "This is a test string") attrString.append(attachment.string) editor.attributedText = attrString
Declaration
Swift
public var string: NSAttributedString { get }
-
Name of the content contained within the
Attachment
Declaration
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
EditorView
Declaration
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 }
-
EditorView
containing 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
.zero
Declaration
Swift
public weak var offsetProvider: AttachmentOffsetProviding?
-
Name of the content for the
EditorView
See also
EditorView
Declaration
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
image
Image 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
contentView
Content view to be hosted within the attachment
size
Size rule for attachment
backgroundColor
Background 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
isSelected
true
to set selected, elsefalse
-
Causes invalidation of layout of the attachment when the containing view bounds are changed
See also
BoundsObserving
Declaration
Swift
public func didChangeBounds(_ bounds: CGRect, oldBounds: CGRect)
Parameters
bounds
Updated bounds
-
Removes this attachment from the
EditorView
it 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
EditorView
in the range of string in which this attachment is contained.Declaration
Swift
open func addedAttributesOnContainingRange(rangeInContainer range: NSRange, attributes: [NSAttributedString.Key : Any])
Parameters
range
Affected range
attributes
Attributes applied
-
Declaration
Swift
open func removedAttributesFromContainingRange(rangeInContainer range: NSRange, attributes: [NSAttributedString.Key])
Parameters
range
Affected range
attributes
Attributes 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) -> CGRect
Parameters
textContainer
Text container for attachment
lineFrag
Line fragment containing the attachment
position
Position in the text container.
charIndex
Character 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()