Components
Paywall
What Pro unlocks, a plan picker and a trial call to action. Built in all 5 Effect UI styles, in light and dark mode.










Source: Ledger
PaywallView.swift in the free Ledger style. It needs Ledger's Theme.swift, which comes with the style: join early access on the home page and it's emailed to you.
import SwiftUI
private enum Plan: String, CaseIterable, Identifiable {
case yearly, monthly
var id: String { rawValue }
var title: String { self == .yearly ? "Yearly" : "Monthly" }
var price: Double { self == .yearly ? 59.99 : 6.99 }
var perMonth: String { self == .yearly ? "$5.00 / mo" : "$6.99 / mo" }
var subtitle: String {
self == .yearly ? "14-day free trial, then billed yearly" : "Billed monthly, cancel anytime"
}
}
private struct Feature: Identifiable {
let id = UUID()
let title: String
let detail: String
let free: FeatureValue
let plus: FeatureValue
}
private enum FeatureValue {
case text(String), included, excluded
}
private let features: [Feature] = [
Feature(title: "Linked accounts", detail: "Banks, cards, loans and brokerages", free: .text("2"), plus: .text("Unlimited")),
Feature(title: "Custom categories", detail: "Rename, split and nest", free: .excluded, plus: .included),
Feature(title: "CSV export", detail: "Any account, any date range", free: .excluded, plus: .included),
Feature(title: "Net-worth tracking", detail: "Assets, debts and the trend", free: .excluded, plus: .included),
Feature(title: "Budgets and alerts", detail: "Monthly limits by category", free: .included, plus: .included),
]
struct PaywallView: View {
@State private var plan: Plan = .yearly
private let columnWidth: CGFloat = 76
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: Theme.Space.xxl) {
topBar
intro
comparison
planSelector
if plan == .yearly {
trialTimeline
.transition(.opacity.combined(with: .move(edge: .top)))
}
}
.padding(.horizontal, Theme.Space.margin)
.padding(.top, Theme.Space.sm)
.padding(.bottom, Theme.Space.xl)
}
.scrollIndicators(.hidden)
.paperBackground()
.safeAreaInset(edge: .bottom) { actionBar }
.animation(Theme.Motion.surfaceEnter, value: plan)
}
// MARK: Sections
private var topBar: some View {
HStack {
IconButton(symbol: "xmark")
Spacer()
Button("Restore purchase") {}
.buttonStyle(TextButtonStyle(color: Theme.onSurfaceVariant))
}
}
private var intro: some View {
VStack(alignment: .leading, spacing: Theme.Space.md) {
Tag("Tilde Plus")
Text("Every account,\nin one ledger.")
.ledgerType(.headlineLg)
.foregroundStyle(Theme.onSurface)
.fixedSize(horizontal: false, vertical: true)
Text("Plus removes the limit on accounts and adds the tools for planning further ahead: your categories, your exports, your net worth.")
.ledgerType(.bodyMd)
.foregroundStyle(Theme.onSurfaceVariant)
.fixedSize(horizontal: false, vertical: true)
Hairline(strong: true).padding(.top, Theme.Space.sm)
}
}
private var comparison: some View {
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .firstTextBaseline) {
MicroLabel("What you get")
Spacer()
MicroLabel("Free").frame(width: columnWidth, alignment: .trailing)
MicroLabel("Plus", color: Theme.onSurface).frame(width: columnWidth, alignment: .trailing)
}
.padding(.bottom, Theme.Space.sm)
Hairline(strong: true)
RuledStack(closed: true) {
ForEach(features) { f in
LedgerRow(title: f.title, subtitle: f.detail) {
HStack(spacing: 0) {
cell(f.free, emphasised: false)
cell(f.plus, emphasised: true)
}
}
}
}
}
}
@ViewBuilder
private func cell(_ value: FeatureValue, emphasised: Bool) -> some View {
let color = emphasised ? Theme.onSurface : Theme.onSurfaceMuted
Group {
switch value {
case .text(let s):
Text(s).font(.system(size: 13, weight: emphasised ? .semibold : .regular, design: .monospaced))
case .included:
Image(systemName: "checkmark").font(.system(size: 13, weight: .semibold))
case .excluded:
Text("\u{2014}").font(.system(size: 13, weight: .regular, design: .monospaced))
}
}
.foregroundStyle(color)
.frame(width: columnWidth, alignment: .trailing)
}
private var planSelector: some View {
VStack(alignment: .leading, spacing: Theme.Space.sm) {
SectionHeader(title: "Choose a plan")
VStack(spacing: Theme.Space.sm) {
ForEach(Plan.allCases) { p in
PlanRow(plan: p, selected: plan == p) {
withAnimation(Theme.Motion.stateChange) { plan = p }
}
}
}
.padding(.top, Theme.Space.xs)
}
.sensoryFeedback(.selection, trigger: plan)
}
private var trialTimeline: some View {
VStack(alignment: .leading, spacing: 0) {
SectionHeader(title: "How the trial works")
RuledStack {
timelineRow(date: "Today", title: "Full access to Plus", detail: "Link every account and set up categories")
timelineRow(date: "Dec 9", title: "A reminder from us", detail: "Two days before your trial ends")
timelineRow(date: "Dec 11", title: "Billed $59.99", detail: "Cancel before then and pay nothing")
}
}
}
private func timelineRow(date: String, title: String, detail: String) -> some View {
LedgerRow(title: title, subtitle: detail) {
Text(date)
.ledgerType(.numeralMd)
.foregroundStyle(Theme.onSurfaceVariant)
.frame(width: 64, alignment: .leading)
} trailing: {
EmptyView()
}
}
private var actionBar: some View {
BottomActionBar {
Button(plan == .yearly ? "Start free trial" : "Subscribe for $6.99 a month") {}
.buttonStyle(.ledgerPrimary)
.contentTransition(.opacity)
Text(plan == .yearly
? "Free for 14 days, then $59.99 a year. Cancel anytime in Settings."
: "$6.99 a month. Renews monthly until you cancel in Settings.")
.ledgerType(.bodySm)
.monospacedDigit()
.foregroundStyle(Theme.onSurfaceMuted)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.top, Theme.Space.sm)
.contentTransition(.opacity)
}
}
}
private struct PlanRow: View {
let plan: Plan
let selected: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: Theme.Space.md) {
radio
VStack(alignment: .leading, spacing: Theme.Space.xxs) {
HStack(spacing: Theme.Space.sm) {
Text(plan.title)
.ledgerType(.headlineMd)
.foregroundStyle(Theme.onSurface)
if plan == .yearly { Tag("Save 28%") }
}
Text(plan.subtitle)
.ledgerType(.bodySm)
.foregroundStyle(Theme.onSurfaceVariant)
}
Spacer(minLength: Theme.Space.sm)
VStack(alignment: .trailing, spacing: Theme.Space.xxs) {
Text(Money.format(plan.price, decimals: 2))
.ledgerType(.numeralMd)
.foregroundStyle(Theme.onSurface)
Text(plan.perMonth)
.font(.system(size: 13, weight: .regular, design: .monospaced))
.foregroundStyle(Theme.onSurfaceMuted)
}
}
.padding(.horizontal, Theme.Space.md)
.padding(.vertical, Theme.Space.md)
.frame(minHeight: 72)
.background(
RoundedRectangle(cornerRadius: Theme.Radius.md, style: .continuous)
.fill(selected ? Theme.primaryTint : Color.clear)
)
.overlay(
RoundedRectangle(cornerRadius: Theme.Radius.md, style: .continuous)
.strokeBorder(selected ? Theme.primaryInk : Theme.rule, lineWidth: selected ? 1.5 : 0.5)
)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityAddTraits(selected ? .isSelected : [])
}
private var radio: some View {
ZStack {
Circle()
.strokeBorder(selected ? Theme.primaryInk : Theme.onSurfaceMuted, lineWidth: 1.5)
Circle()
.fill(Theme.primaryInk)
.frame(width: 10, height: 10)
.scaleEffect(selected ? 1 : 0.01)
.opacity(selected ? 1 : 0)
}
.frame(width: 20, height: 20)
}
}
#Preview("Light") {
PaywallView()
}
#Preview("Dark") {
PaywallView().preferredColorScheme(.dark)
}
More screens





