Advent · Day 7

This one opens on December 7.

Every door opens at midnight Pacific.

See the calendar

Pattern · Media

Photo Markup SwiftUI Block

Photo Markup SwiftUI Block is a paid SwiftUI pattern in SwiftPieces Pro. Draw on a photo with a pen, marker and highlighter, drag out arrows, place text and erase, with undo and redo. iOS 17.0 and later. SwiftPieces Pro is $199 once.

Draw on a photo with a pen, marker and highlighter, drag out arrows, place text and erase, with undo and redo.

Buyers also search for this as a SwiftUI section.

Facts
Price$199 once
iOSiOS 17.0 and later
LicenseA per-developer commercial license for unlimited personal and commercial apps, including client work. Do not resell or redistribute the source as a template or UI kit.
DependenciesNo third-party packages. Apple frameworks only.
Files1 Swift file in the install.

The markup tool of a photo editor as one section. Smoothed strokes in a pen, a broader marker and a translucent highlighter, arrows you drag out, text labels you place, edit and move, and an eraser that lifts whole items. Ink comes from five swatches and a width slider, and every item is a Codable value normalized to the photo, so a drawing renders onto the full-resolution photo at any size.

  • SwiftUI
  • iOS 17.0+
  • photo-markup
Get SwiftPieces Pro

$199 once, every piece included. See how installing works · Sign in

Proof

This targets iOS 17.0 and later. On iOS 26 it uses Liquid Glass. On iOS 17 through iOS 18 it uses a material fallback, including when Reduce Transparency is on.

No simulator still is published for this page yet.

01

What's included

SwiftUI source you own, built on Apple frameworks only.

  • Pen, marker and highlighter with smoothed strokes
  • Arrows, and text you tap to edit and drag to move
  • An eraser that lifts whole items
  • Five swatches including the system colour picker, and a width slider
  • Codable items and render(over:) at full resolution

Used in

Photo Editor (screen)

02

Implementation notes

How it behaves, what it handles, and the decisions behind it.

The photo sits on a stage, and you draw straight on it. The pen draws a narrow line, the marker a broader one and the highlighter a wide translucent band that multiplies with the photo. All three are smoothed through the midpoints of your touches. The arrow tool drags out an arrow with its head sized to the line. The text tool places a label you type into. Tap any label to edit it again, or drag it into place, and a label left empty disappears. The eraser lifts whole items it touches. Above the tools, undo and redo sit at either end of the row, with the tool's name between them. Under the tools are five swatches (your text colour, the accent, white, black and the system colour picker) and a width slider drawn as a growing wedge. Apple Pencil draws through the same gesture.

Notes

  • PhotoMarkupBlock(image:drawing:) binds a PhotoMarkupBlock.Drawing. Passing nil draws a ghost.
  • A Drawing is a list of Items, in drawing order. Each Item has a kind (pen, marker, highlighter, arrow or text), points normalized 0...1 to the photo, an Ink (plain sRGB numbers), a width as a fraction of the photo's width, and text. Everything is Codable, so a drawing is saved with the edit and redrawn at any size.
  • drawing.render(over:) paints the drawing on the photo at its own resolution. Widths and text sizes scale with the image. It uses UIKit drawing, so call it on the main actor.
  • PencilKit is not used. Items stay plain values you can store, diff and render anywhere.
  • Undo and redo keep up to 50 steps of the block's own changes. A screen around it can keep its own history too, as Photo Editor does.
  • The swatch for your text colour resolves the theme's colour at the moment you draw, so a stroke keeps its colour if the appearance changes later.
  • VoiceOver reads each tool and swatch, marks the chosen one, reads text labels and offers editing, and the width slider is adjustable.
  • PhotoMarkupBlockExample is the preview: the painted sample photo with the sun circled in red and a "golden hour" caption.

Theming

The block reads these tokens:

  • surface for the stage.
  • textPrimary for the tool name, the chosen tool, the ink swatch, the selection rings and the width wedge.
  • textSecondary for the other tools, textTertiary for undo and redo when there is nothing to undo.
  • fill behind the chosen tool, separator around swatches.
  • accent as a swatch.
  • radius.lg and motion.snappy.

03

Keep building

Pieces that work well next to this one.