Advent · Day 11

This one opens on December 11.

Every door opens at midnight Pacific.

See the calendar

Pattern · Commerce

Gift Card SwiftUI Block

Gift Card SwiftUI Block is a paid SwiftUI pattern in SwiftPieces Pro. Send a gift card amount first: swipe stationery card designs and type the amount, write the note on its back, pay, and seal it in an envelope, with a code field to redeem it. iOS 17.0 and later. SwiftPieces Pro is $199 once.

Send a gift card amount first: swipe stationery card designs and type the amount, write the note on its back, pay, and seal it in an envelope, with a code field to redeem it.

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.
Files2 Swift files in the install.

The gift card flow from Giftlist, amount first, the way you'd hand someone cash. The card designs sit on a carousel you swipe, the amount is set large under them and a keypad with quick amounts types it, inside your limits. Next turns the card over: the note is written on its back in the display face's italic, signed by whoever it's from, with who it's for, their email and when it arrives in rows under it. Pay shows working, done and failed in place, then the card slides into an envelope, the flap folds shut and a wax seal presses on, with the code to copy. The cards are stationery drawn from the theme's blocks, so they take the look of the app they drop into. `GiftCardView` is the card on its own and renders to an image, and `RedeemCode` is the other side: the balance on a card, a code field in groups of four that takes a paste and checks the last character before your server, and a balance that counts in.

  • SwiftUI
  • iOS 17.0+
  • gift-card
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.

  • Amount first: a carousel of card designs over the amount and a keypad
  • Six stationery designs (Foil, Liner, Ivory, Midnight, Seal, Olive) drawn from your theme's blocks
  • The note written on the card's back, with who it's for, From, and Now or a day and time
  • Pay with working, done and failed in place, then the card sealed in its envelope with its code
  • RedeemCode: the balance, a code field in groups of four with a check character, and a counting balance
  • GiftCardView renders the card to an image for email or sharing

Used in

Gift App (template)

02

Implementation notes

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

The card sits on top at a credit card's proportions and is drawn from the draft as it changes: the design's ground, your brand line and the amount, which rolls digit by digit when another is picked. Writing the message or From turns the card over to show the back with the note, and leaving the field turns it face up again. Design offers four grounds as small cards that lift when picked: Ribbon (the surface with a red ribbon tied across), Ink, Red (your accent) and Ember (a rising glow from pink to a wine core). Amount offers your amounts as chips and Other, a currency field kept inside your minimum and maximum, which says so in red when a typed amount falls outside them. For takes their name and email, a message of up to 200 characters with a running count, and From. Arrives is Now, or Pick a day with a date and time no earlier than now (tomorrow at nine to start). Pay carries the amount, stays quiet with a line saying what's missing until the card can go, then runs your closure through working, a check on the button and the card, or the error's message under it.

RedeemCode is the other side, in the same file set. A field in three groups of four (or as many as you ask for) takes typing or a paste: letters are upper-cased, spaces and dashes dropped, and look-alikes read the way codes are printed (O as 0, I and L as 1). The current box is outlined as it fills. The last character is a check over the rest, so a mistyped code says "That code doesn't look right" at once, without a round trip. Redeem runs your closure, which returns the amount added; the block shows a check and counts the balance up to its new total.

Notes

  • GiftCardComposer(draft:designs:amounts:range:currencyCode:brand:onPay:) binds a GiftCardDraft: designID, amount (Decimal), recipientName, recipientEmail, message, from and deliverAt (nil sends now). It is a section: no navigation stack, background, padding or scroll view of its own, so place it in a ScrollView with .padding(.horizontal, 20).
  • designs defaults to GiftCardDesign.standard. A GiftCardDesign is an id, title and Style: .ribbon, .ink, .accent or .ember.
  • amounts are the chips (25, 50, 100 and 150 by default) and range the limits for Other (10 to 500). Pay is enabled once the amount is in range, there's a name, and the email has an @ and a dot after it; GiftCardDraft.looksLikeEmail(_:) is that check, and your server has the final say.
  • onPay is async throws and gets the draft: charge it, issue a code with RedeemCode.makeCode(), and schedule the email for deliverAt. Throwing shows the error's errorDescription, or "Your payment didn't go through. Try again.", under Pay.
  • GiftCardView(design:brand:amount:currencyCode:message:from:isBack:) is the card on its own for a wallet, a receipt or the redeem screen. GiftCardView.image(_:width:scale:theme:) renders it to a UIImage with ImageRenderer, to attach to the email or share.
  • RedeemCode(groups:checksum:balance:currencyCode:onRedeem:): onRedeem is async throws and returns the amount the code added. A thrown error's description, or "That code didn't work. Check it and try again.", shows under the field and clears it. checksum: false skips the local check for codes you don't issue.
  • Codes use 32 characters (digits and letters without O, I, L and U). RedeemCode.normalize(_:), checkCharacter(for:), isValid(_:), makeCode(groups:) and formatted(_:) ("7K2Q-M9XP-4H1C") are public, so your server and your emails print and check codes the same way.
  • Haptics: a selection tick for designs and amounts, a light tap on Pay, success when a card is paid or redeemed, an error when either fails.
  • VoiceOver reads the card as "Ember gift card, $100" with the message as its value, designs as buttons marked selected, the code field as "Gift card code" with each character spoken, and announces payments, redemptions and failures.
  • Dynamic Type: chips wrap onto more lines, the code boxes step down a size before they would clip, and the card's amount shrinks to fit.
  • Reduce Motion turns the flip into a fade, keeps the picked design still, and the balance jumps to its total instead of counting.
  • GiftCardComposerExample at the end of GiftCardComposer.swift is Sam's card for Maya in Giftlist: Ember, $100, a birthday note, arriving tomorrow at nine. RedeemCodeExample at the end of RedeemCode.swift is Maya redeeming it.

Theming

  • Reads SPTheme from @Environment(\.spTheme) and requires the design-system item.
  • The amount on the card is the one display moment: type.numeral(40) with type.tracking(for:); the brand line is type.headline. The redeemed balance is type.numeral(44).
  • Section labels are type.footnote semibold, upper-cased, in textSecondary. Fields and chips sit on fill with radius.md and a 1 point separator stroke that turns textPrimary when focused.
  • Picked chips and Pay are the accent with accentOn. The Red design is your accent; Ribbon's ribbon is a fixed red and Ember's ramp fixed colours, so a card looks the same in any theme.
  • The code boxes are fill with the smaller of radius.sm and 8; the current one is outlined in textPrimary, a wrong code in danger, a redeemed one in success.
  • Changes use motion.smooth and motion.snappy, presses motion.standard.

Requirements

  • None. Charging for the card, issuing codes and sending the email are your server's.

03

Keep building

Pieces that work well next to this one.