Skip to content

Repository files navigation

Preview Utilities

Utilities for SwiftUI previews.

A collection of modifiers, views, extensions, and other utilities for building previews in SwiftUI.

Latest documentation: v0.4.1.

See Package Documentation for documentation of earlier versions.

Note

Package documentation is actively being written. Many of the utilities in this package have not been thoroughly documented yet.

Essentials

Debug Overlay

Visualize the boundaries, origin, and safe areas of a view, without impacting its layout.

Apply debugOverlay() to a view to overlay the debug visualization:

Text("Sphinx of Black Quartz")
    .font(.title)
Text("Judge my Vow")
    .font(.title)
    .debugOverlay()

Debug overlay with default configuration.

See the Debug Overlay documentation for more details.

Debug Alignment Guides

Visualize the alignment guides of a view, without impacting its layout.

Apply debugAlignmentGuide(_:_:) to overlay a visualization of the alignment guides:

Text("A new age\ndoes not begin all of a sudden")
.font(.title)
.multilineTextAlignment(.trailing)
.debugAlignmentGuide(.trailingFirstTextBaseline,
    .lineWidth(8),
    .fixedLength(vertical: 200),
    .anchor(.trailing)
)

Text displaying a trailing first text baseline alignment guide using example traits.

See the Debug Alignment Guide documentation for more details.

Floating Caption

Add a floating caption, border, and size information to a view, without impacting its layout.

Apply the floatingCaption(_:_:) modifier to a view to overlay a floating caption, and optionally draw a border over the owner view:

Circle()
.fill(.tertiary)
.frame(width: 80, height: 80)
.floatingCaption(
    "A `Circle` Shape",              // caption localized string
    .height,                         // prints the height of the owner view
    .alignment(.outerLeadingBottom), // sets the caption alignment
    .colorStyle(.indigo),            // sets the caption and border color
    .borderWidth(4)                  // sets the border width
)

Floating caption with example traits and explanations.

See the Floating Caption documentation for more details.

Other utilities

Other utilities available in this package:

  • Several FormatStyle implementations for a variety of cases.
  • The Floating Alignment API for floating content in an overlay.
  • PreviewCaption to add a caption to previews that are also easy to read in code.
  • Several image generators that can be used to produce preview images synchronously and asynchronously with different isolation contexts.

Future Development

This package is also a catch-all for experimental utilities that do not have an individual project of their own. Some utilities and extensions that will eventually move elsewhere:

  • Extension inits for Slider, Picker with support for collections and style formatters.
  • Extensions for OptionSet to identify each option through a shift value.

As this package moves towards a 1.0 release, many of these unrelated utilities will move to separate packages.

License

Preview Utilities is licensed under the MIT License.


Written with ♥ in San Francisco, California.

About

A collection of utilities for building previews in SwiftUI.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages