Skip to main content
100%

Image Attachment to a Text Object

✓ Published0🌍 Public
KKevinGutowski
Last edited Jun 10, 2020
Created on Jun 10, 2020

This example demonstrates how to embed an image attachment directly into a specific position within a text object in Sketch. The code uses the Sketch API to access the selected layer and its editing delegate, then modifies its `NSTextStorage` by replacing a character range with an attributed string containing the attachment. It relies on `NSFileWrapper`, `NSTextAttachment`, and `NSAttributedString` to load and insert the image, setting its display bounds. The image path is hardcoded to a local file, and the insertion occurs at character index 4 while editing is active.

AI-generated description

Similar vizzes