LAYMAN: Figma to Swift Generator, 2025

LAYMAN Logo, 2025

Engineering & Design

LAYMAN — Figma to SwiftUI Generator

August 2024 — Present

LAYMAN is a Figma Dev Mode plugin that converts Figma Frames into SwiftUI View code.

Below is a fork of the original project README.


Render as a Single File

The generator can be configured to render all code as a single file. The file can be copy-pasted into a single Swift file that should compile without any additional dependencies.

This is useful for testing and observing components during design.

The following generator settings must be set:

Generator Tags

Generator tags can be used to define custom behaviours, properties, or conversions for a layer.

Tags are denoted by {} and are placed at the end of a layer name.

Syntax:

{tag props}

Example:

Layer Name {geo name: geometryScreen, maxWidth}

{aspect}

Alts: {aspectRatio}

Props:

Aspect Ratio.

Applies an .aspectRatio() modifier to the view.

If mode is set to fit, the aspect ratio is maintained while fitting the view within the frame. If mode is set to fill, the aspect ratio is maintained while filling the frame.

If ratio is set, a custom aspect ratio is used. Otherwise the aspect ratio of the frame is used.


{convert}

Alts: {converter}

Props:

Custom View Conversion.

Converts the layer to a custom defined view.

Only the custom view name is included if no additional parameters are set.

If props is present, the properties of the original view are included in the view. For text layers, this is the text content.

If children is present, the children of the layer are included in the view.

If mod is present, the modifiers for the layer are included in the view.

If context is set, the custom context will be made available within the view.

If params is set, the string is rendered as the view’s parameters.

If a layer name contains more than one {convert} tag, only the first tag is considered.


{geo}

Alts: {geometry}

Props:

Geometry Reader.

Wraps the view in a GeometryReader.

The size of the geometry is used in place of any fill sizing properties.

If maxWidth is set, the width of the geometry is applied to the maximum size of the view. The same applies for maxHeight. Using both will use the full size of the geometry for the maximum size of the view. If neither is set, the geometry is ignored for sizing the view.


{hide}

Alts: {hidden}

Hide Layer.

Remove the view & its children from rendering.


{import}

Props:

Library Import.

If Preview mode is set, adds a library import to the top of the file.


{mod}

Alts: {modifier}

Props:

View Modifier.

Applies a Modifier to the View.

If modStack is set, the modifier is applied to the named modifier stack. For example, style would apply the modifier to the same level as .background() & .border() modifiers. If no stack is found matching the name, the modifier is added to the post stack.


{reader}

Props:

Read the size from a parent GeometryReader.

The size of the parent geometry is used in place of any fill sizing properties.

If geo is set, the geometry with the matching name is used. If no name is set, the closest parent geometry is used. If no geometry is found matching the name, the reader is ignored.

If maxWidth is set, the width of the geometry is applied to the maximum width of the view. The same applies for maxHeight. Using both or neither will use the full size of the geometry for the maximum size of the view.


{safeArea}

Props:

Ignore edges of the safe area.

Allows content to flow outside the bounds of the safe area.

ignore must be present. If set, the specified edges are ignored. If no edges are set, all edges are ignored.


{scroll}

Alts: {scrollView}

Props:

Scroll View.

Wraps the view in a ScrollView.

If content is set, the content is wrapped in the scroll view.


{view}

Props:

Custom View.

Wraps the layer in a custom defined view.

If context is set, the custom context will be made available within the view.

If params is set, the string is rendered as the view’s parameters.

If a layer name contains more than one {view} tag, views are nested within each other. The first tag is the outermost view.


{viewModel}

Props:

ViewModel Properties.

Adds a property to the ViewModel. Creates either a variable or a function.

This is useful for creating custom placeholders in the ViewModel panel. These placeholders can be used to manage the state of any element in the main view.


SwiftUI Control Transformations

Layers names can be transformed into SwiftUI controls. For example, a layer named Divider will be exported as a SwiftUI Divider view.

Note: Component Instances are not transformed.

Example:

Accept Button

↓↓

Button(action: $viewModel.acceptButtonAction) {
  // Accept Button Layer
}

Button

A layer name that contains Button will be exported as a SwiftUI Button view.

A custom action will be added to the ViewModel panel.

Divider

A layer name that contains Divider will be exported as a SwiftUI Divider view.

If the layer contains auto layout, the divider will be exported with padding applied.

If the layer contains fixed sizing, the divider will be exported with a fixed size along the major axis of the parent view.

Picker

A layer name that contains Picker will be exported as a SwiftUI Picker view.

The layer is transformed into a Picker view and children become selectable items. The name of the layer is used as the label for the Picker.

A custom selection binding, as an integer, will be added to the ViewModel panel. Item 1 is selected by default.

Tip: Wrap the Picker in a Form or List view to display the selection label.

SecureField

A layer name that contains SecureField will be exported as a SwiftUI SecureField view.

If the layer is a text layer, the text content will be used as the placeholder text.

A custom text binding will be added to the ViewModel panel.

Slider

A layer name that contains Slider will be exported as a SwiftUI Slider view.

A custom value binding will be added to the ViewModel panel.

Spacer

A layer name that contains Spacer will be exported as a SwiftUI Spacer view.

TextField

A layer name that contains TextField will be exported as a SwiftUI TextField view.

If the layer is a text layer, the text content will be used as the placeholder text.

A custom text binding will be added to the ViewModel panel.

Toggle

A layer name that contains Toggle will be exported as a SwiftUI Toggle view.

A custom state variable will be added to the ViewModel panel.


Generator Settings

Effects

Backdrop Blur Output

Technique used to render backdrop blur effects.

Effect Style Output

How Figma Effect Styles are rendered.

Materials on Shapes

Swift Materials can be applied to shapes as either the background of the content area or as the shape fill.

Fonts

Custom Fonts

Allow custom fonts to be exported, or use system fonts. The system font can match to constants or take on dynamic sizes & styles from the design.

Font Weight Matching

Font weights can be matched to system font weights or use the name of the font weight in the design (unsupported).

Letter Spacing Style

iOS renders spacing in text by kerning characters. Figma render spacing in text by tracking characters.

Line Height

Figma allows setting the line height, whereas iOS only natively supports spacing between lines.

System Font Size

The iOS Dynamic Type system allows for text to be resized based on the user’s preferred text size.

When Custom Fonts is set to System, this setting defines how to translate the font sizes in the design to the system font size.

Text Style Output

Text styles can be exported as custom view modifiers or rendered in place.

Generator

Component Instances

Instances of components can be exported as a single component, or as a deep render of the component.

Error Output

Choose whether to output errors in the console terminal. In the Figma Desktop app, Menu Bar > Plugins > Development > Show/Hide Cconsole.

Instance Layer Tags

Layer Tags can be processed on Component Instances. This feature can be disabled, for example, when main components were already rendered with the tags.

Layer Tags

Layer Tags are special tags that can be used to define custom behaviours or properties to a layer. Tags are denoted by {} and are placed at the end of a layer name.

Node Parent

By default, the Figma API does not provide the parent of the selected node. This setting allows the document to be crawled to determine the parent of the selected node. Very slow, as the entire document may be crawled.

Progress Bar

The total amount used for the progress bar displayed in the console terminal. The progress bar is used to indicate the progress of the code generation process. In the Figma Desktop app, Menu Bar > Plugins > Development > Show/Hide Cconsole.

Render Mode

The render mode determines how the code is generated in the main SwiftUI panel. The code can be rendered as a full preview, just a struct, or as only view code.

Vector Images

Vector images can be rendered as Path views or linked as a custom view. Vectors are rendered in the Vector Images panel.

Note: Vector image render is very slow.

METADATA

Component Descriptions

Figma components may contain multiline descriptions. These descriptions can be exported as multiline comments in the output code.

Figma components may contain links to documentation, etc. These links can be exported as comments in the output code.

Component Set Names

Figma components may be part of a component set. The name of the component set can be exported as a comment with each component variant in the output code.

Document Properties

The entire document’s properties can be exported as a single line JSON string in the Document Properties panel.

Note: This feature is currently in beta. Only the document ID can be exported. lol

Layer Names

Figma layers have names. These names can be exported as comments in the output code.

Layer Properties

All properties of a layer can be exported as a single line JSON string in the output code.

Local Variables

All variables local to the current document can be exported in the Local Variables panel.

Note: This feature is currently in beta. Only some variables can be exported.

Team Libraries

Figma teams may have libraries shared across the team. All libraries present in the current document can be exported in the Team Libraries panel.

Note: This feature is currently in beta.

SWIFTUI

Control Actions

SwiftUI controls may contain actions. Placeholder action can be exported inline with the control or as a separate function in the ViewModel panel.

Duplicate Actions

Two layers with identical names will produce ViewModel functions with identical names.

A number suffix can be added to any duplicates found.

SwiftUI Controls

Layer names can be transformed into SwiftUI controls. For example, a layer named Divider will be exported as a SwiftUI Divider view.

ViewModel Actor

SwiftUI provides concurrency with thread Actors. The ViewModel can be exported with the @MainActor global actor to ensure all operations are performed on the main thread.

Output

Dynamic Size

Figma layers may contain dynamic sizing properties, such as fill width or height. The Figma API does not provide these properties. This setting allows for the dynamic sizing properties to be exported.

To use this feature, Node Parent must be set to Crawl Document.

Image Aspect Ratio

Images can be exported with their aspect ratio preserved. A resizable modifier is applied to the image view to respect the aspect ratio.

Layer Mask

Figma layers may contain masks. Masking is not currently supported by the generator. Masks can be disabled from output or rendered as shapes for testing.

No Layer Name

When a layer contains no name, it must be given a unique name to be exported. This setting chooses the default name to be given to layers without a name.

Transforms

Opacity Transforms

Figma represents opacity as 33% percentages. SwiftUI represents opacity as 0.33 decimals. This setting allows for the conversion of opacity values.

Variable Transforms

Exact values used in Figma may not translate directly to SwiftUI. This setting enables transformations of variables to better match SwiftUI.

When a Figma variable is transformed, a _mod suffix is added to the variable name.

Variables

Duplicate Variables

Figma variables may be used multiple times in a design. This setting allows for the identification of duplicate variables.

Figma Variables

Figma variables used in the design are exported in a separate Variables panel. This setting enables the rendering the value of each variable in place of the variable name in the output code.

Changes & Additions

This plugin is supplied with extended support for SwiftUI, as well as many fixes & opinionated changes.

Things to Note

also: in the interest of time lots of any. sorry mom.

Upcoming Fixes

Upcoming Features