skip to content

Visual Content

Text, images, symbols, shapes and visual effects: the content SwiftUI draws inside a layout. Interviewers ask how text scales, images load and when to drop to custom drawing.

on this pageshow

explore

questions

18

In SwiftUI, how does an SF Symbol from Image(systemName:) differ from an asset-catalog Image(_:) in how it sizes and takes colour?

level: juniorimportance: must knowfreq 70%

answer

  1. glyph versus picture
  2. the font sizes a symbol
  3. imageScale is relative, not absolute
  4. natural point size until resizable()
  5. template images take foregroundStyle

basics

~20 s

An SF Symbol behaves like a text glyph: font(:) and imageScale(:) size it and foregroundStyle colours it. A bitmap asset draws at its natural point size in its own colours until you make it resizable() or template-rendered.

solid answer

~50 s

`Image(systemName:)` loads a vector symbol that SwiftUI sets like a character of text: it takes its point size and weight from the environment's `font`, `imageScale(.small)`, `.medium` or `.large` adjusts it relative to that font, and it draws as a template, so `foregroundStyle` colours it. `Image("chef-hat")` loads a picture from the asset catalog at its natural point size, choosing the @2x or @3x variant for the screen; a font does not resize it, so you add `resizable()` and an aspect ratio to scale it. It keeps its authored colours unless the asset's Render As setting or `renderingMode(.template)` makes it a template. A custom symbol stored as a symbol image set is the exception: it behaves like an SF Symbol. Both initialisers take a string, so a typo appears only at runtime; since iOS 17, Xcode's generated `ImageResource` constants such as `Image(.chefHat)` catch asset typos at compile time.

code

swift · 27 lines
swift
import SwiftUI

struct RecipeHeader: View {
    let title: String
    let minutes: Int

    var body: some View {
        HStack(spacing: 12) {
            Image("chef-hat")
                .resizable()
                .scaledToFit()
                .frame(width: 44, height: 44)
            VStack(alignment: .leading) {
                Text(title)
                    .font(.headline)
                Label("\(minutes) min", systemImage: "clock")
                    .font(.subheadline)
                    .foregroundStyle(.secondary)
            }
            Spacer()
            Image(systemName: "star.fill")
                .font(.title3)
                .imageScale(.large)
                .foregroundStyle(.yellow)
        }
    }
}

go deeper

for a junior

Recall the contrast: symbols size with font and imageScale and colour with foregroundStyle; asset bitmaps keep their natural size and colours until resizable() or template rendering.

for a middle

Explain template versus original rendering, why imageScale is relative to the font, and how the @2x and @3x variants set an asset's point size.

for a senior

Show production habits: ImageResource constants to catch renamed assets, custom symbol image sets for brand icons that follow Dynamic Type, and template icons that adapt to dark mode.

for a principal

Frame the icon policy a team adopts: system symbols first, custom symbols for brand marks, bitmaps only for photos, so icons scale, tint and stay consistent across the app.

## Two kinds of picture behind one type SwiftUI's `Image` is a single view type, but the picture behind it can be one of two very different things. An **SF Symbol**, created with `Image(systemName: "star.fill")`, is a vector glyph from Apple's symbol set, designed to sit beside text in nine weights and three scales. An **asset image**, created with `Image("chef-hat")`, is a picture you added to the app's asset catalog: usually a PNG, JPEG or HEIC bitmap supplied at @2x and @3x, sometimes a PDF or SVG vector. Apple's documentation describes `Image` as a late-binding token: the system resolves the actual picture only when it is about to draw it in an environment, which is why the environment (font, colour, scale) can change how the same `Image` value looks. ## How an SF Symbol takes its size A symbol is sized the way text is sized, not the way a photo is. - **`font(_:)`** sets its point size and weight. `Image(systemName: "clock").font(.subheadline)` matches a subheadline `Text` beside it, and because text styles follow Dynamic Type, the symbol grows with the user's text size. - **`imageScale(_:)`** takes `Image.Scale.small`, `.medium` or `.large` and scales the symbol *relative to the current font*. Apple's documentation calls it a scale "to apply to vector images relative to text"; it is not a point size. - **`fontWeight(_:)`** or a weighted font changes the stroke weight, so a symbol can match bold text. - **`resizable()`** works on a symbol too, but it then scales the glyph as a picture to whatever frame it gets, losing its tie to the neighbouring text's size. Inside a `Label` or interpolated into a `Text`, a symbol also lines up with the words around it, which is why toolbar and list icons are almost always symbols. ## How an asset image takes its size A bitmap asset has a fixed natural size in points: a 300 × 300-pixel @3x image lays out as 100 × 100 points. Until you call `resizable()` it keeps that size, and a font has no effect on it. To scale it you follow the usual chain: 1. `resizable()` lets the image take the size its frame offers. 2. `scaledToFit()` or `scaledToFill()` (both shorthands for `aspectRatio(contentMode:)`) keep the original proportions. 3. A `frame` decides the size, and `clipped()` hides any overflow from fill. The exception is a **custom symbol** exported from the SF Symbols app into a symbol image set in the catalog: `Image("custom.whisk")` then behaves like a system symbol, sized by the font and tinted by the foreground style. ## Colour: template versus original | | SF Symbol | Bitmap asset | |---|---|---| | Default rendering | template: the foreground style fills its shape | original: its own pixels | | Sized by | `font(_:)`, `imageScale(_:)` | its natural point size, or `resizable()` plus a frame | | Recoloured by | `foregroundStyle`, `symbolRenderingMode(_:)` | only after `renderingMode(.template)` or Render As Template | | Typo in the name | an empty image at runtime | an empty image at runtime, or a compile error with `ImageResource` | A **template** image uses only its shape (its alpha channel) and fills it with the current foreground style; an **original** image draws its own colours. So `.foregroundStyle(.orange)` turns a symbol orange but leaves a full-colour photo untouched. To tint a single-colour icon PNG, either set Render As to Template Image in the asset catalog or call `renderingMode(.template)` on the `Image`. ## Names, typos and type safety - `Image(systemName:)` and `Image(_:)` both take a `String`, so a misspelt name compiles and shows nothing when the screen runs. - Since iOS 17, `Image(_:)` also accepts an `ImageResource`. Xcode generates a static constant for each catalog image, turning `chef-hat` into `.chefHat`, so `Image(.chefHat)` fails to compile if the asset is renamed or removed. - System symbol names have no such generated constants; check them in the SF Symbols app, which also shows the iOS release each symbol needs. - `Image(decorative:)` and the `label:` initialisers decide what VoiceOver reads; that choice belongs with accessibility rather than rendering. ## What to say in an interview The crisp contrast is: **a symbol is text-like, an asset is picture-like**. Symbols take size and weight from the font and colour from the foreground style; assets keep their natural size and colours until you opt into resizing and template rendering. Naming the custom-symbol exception and `ImageResource` shows you have shipped real screens rather than memorised one example.

  • Why is font(_:) usually better than resizable() and a frame for sizing an SF Symbol?
    A font sets the symbol at a point size, so it tracks Dynamic Type through the text style, keeps its weight matched to the text and lines up with neighbouring words. `resizable()` scales the glyph as a picture to whatever frame it gets, so it no longer follows the text size and can distort if you forget an aspect ratio. Reserve `resizable()` for a large decorative symbol with a fixed frame.
  • What does Image(systemName:variableValue:) add for a symbol such as a signal-strength icon?
    Available since iOS 16, it passes a value from 0 to 1 that symbols with variable layers use to switch layers on progressively, such as the bars of `wifi` or `speaker.wave.3`. Only symbols designed with variable layers respond to it. It lets one symbol show a level without swapping symbol names.

  • An SF Symbol needs resizable() and a frame before it can change size.
  • imageScale(.large) sets an absolute point size for the symbol.
  • foregroundStyle recolours a full-colour asset photo the same way it tints a symbol.
  • A misspelt system symbol name is caught by the compiler.
  • A font modifier scales bitmap asset images along with the text.
open as a page

In SwiftUI, how do you draw a custom shape, such as a fitness app's speed gauge arc, by conforming to the Shape protocol?

level: juniorimportance: must knowfreq 65%

basics

~10 s

Conform a struct to Shape and implement path(in:), building a Path from the CGRect SwiftUI passes in. The shape is itself a view: frame sizes it, and fill or stroke styles it.

open as a page

In SwiftUI, why does Text render **Pending** in bold from a string literal but show the asterisks when it comes from a String variable?

level: juniorimportance: must knowfreq 60%

basics

~20 s

A string literal passed to Text becomes a LocalizedStringKey, and SwiftUI parses inline Markdown in it. A String variable goes through Text's plain-string initializer, which shows the characters as they are; parse runtime Markdown with AttributedString(markdown:).

open as a page

In SwiftUI, why should a transaction row use font(.headline) or another text style rather than .system(size: 17), and how do custom fonts keep scaling?

level: juniorimportance: must knowfreq 70%

basics

~20 s

A text style such as .headline resolves to a size that follows the user's Dynamic Type setting, while .system(size: 17) stays at 17 points. Custom fonts scale through Font.custom(_:size:), like body or like the style named in relativeTo:.

open as a page

In SwiftUI, how do you show a placeholder, the loaded recipe photo and an error state with AsyncImage, and where do image modifiers go?

level: middleimportance: must knowfreq 64%

basics

~20 s

Use AsyncImage's phase initialiser: its closure receives AsyncImagePhase, and you return a placeholder for .empty, the image for .success and an error view for .failure. Image modifiers such as resizable() go on the Image inside the closure.

open as a page

In SwiftUI, why does a thick stroke on a Circle spill past its frame, and how do strokeBorder, trim and StrokeStyle build an activity ring?

level: middleimportance: must knowfreq 60%

basics

~20 s

stroke centres its line on the path, so half the width falls outside the frame; strokeBorder insets first and stays inside. A ring adds trim(from:to:) for progress and a round-capped StrokeStyle, insetting by hand because trim drops strokeBorder.

open as a page

In SwiftUI, how do you show a transaction's amount and date with Text(_:format:) instead of a hand-built string, and what does it handle for you?

level: middleimportance: must knowfreq 65%

basics

~20 s

Text(amount, format: .currency(code: "EUR")) and Text(date, format: .dateTime.day().month()) format the value for the environment's locale when body runs. A relative date formatted this way does not tick; iOS 18 adds Text(.currentDate, format:) styles that update live.

open as a page

In SwiftUI, how do you make recipe photos fill square grid thumbnails without stretching or spilling, and why is clipped() needed?

level: juniorimportance: should knowfreq 60%

basics

~10 s

Chain resizable() and scaledToFill() on the Image, give it a square frame, then clipped(). resizable() alone stretches each axis, fill keeps the aspect ratio but overflows the frame, and clipped() hides the overflow.

open as a page

In SwiftUI, how does renderingMode(_:) differ from symbolRenderingMode(_:), and when do you use monochrome, hierarchical, palette or multicolor?

level: middleimportance: should knowfreq 48%

basics

~10 s

renderingMode(:) works on any Image and chooses template (shape filled with the foreground style) or original (own pixels). symbolRenderingMode(:) works on SF Symbols' layers: monochrome, hierarchical, palette or multicolor.

open as a page

In SwiftUI, how do you put a frosted Material card over a workout photo, and when do you use clipShape versus mask?

level: middleimportance: should knowfreq 50%

basics

~20 s

Back the card with a Material, as in background(.ultraThinMaterial, in: .rect(cornerRadius: 16)), so it blurs the photo behind it. clipShape cuts a view to a shape's outline; mask applies another view's alpha, so it can fade.

open as a page

In SwiftUI, how do lineLimit, truncationMode, minimumScaleFactor and multilineTextAlignment decide what a long merchant name shows in a transaction row?

level: middleimportance: should knowfreq 55%

basics

~20 s

Text wraps without limit by default. lineLimit caps the lines, as a number or an iOS 16 range; truncationMode places the ellipsis; minimumScaleFactor lets text shrink before truncating; multilineTextAlignment aligns lines only within a multi-line Text.

open as a page

In SwiftUI, how do you put a bold orange "Pending" badge inside one line of Text, and why does Xcode warn about Text + Text?

level: middleimportance: should knowfreq 50%

basics

~20 s

Interpolate a styled Text into a Text literal: Text("(merchant) (badge)"), where badge is Text("Pending").bold().foregroundStyle(.orange). The + operator on Text is deprecated in iOS 26 in favour of this interpolation, which keeps the sentence as one localization key.

open as a page

In a SwiftUI recipe grid, AsyncImage thumbnails show their placeholders again and re-download when scrolled back into view; what does AsyncImage cache, and how do you fix it?

level: seniorimportance: should knowfreq 44%

basics

~20 s

Before iOS 27, AsyncImage documents no cache and no download settings: it loads through the shared URLSession. From iOS 27 it caches image data following the transport protocol, init(request:) sets a cache policy and asyncImageURLSession(_:) supplies a session.

open as a page

A SwiftUI workout screen draws a 5,000-sample heart-rate trace as separate Shape views and stutters; when do you switch to Canvas or drawingGroup?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Thousands of Shape views are thousands of views to manage. Canvas draws everything inside one view through a GraphicsContext but loses per-element accessibility and interaction; drawingGroup keeps the views and flattens them into one offscreen image.

open as a page

In a SwiftUI search screen, how do you highlight the matched part of each merchant name with AttributedString when Markdown and Text modifiers cannot express it?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Wrap the merchant name in an AttributedString, find the match with range(of:options:), set attributes such as backgroundColor and font on that range, and pass it to Text. Text draws SwiftUI's attributes per run, and a run's attributes win over modifiers.

open as a page

How far should a SwiftUI app adopt Liquid Glass and custom effects in its own components, versus system controls, when it still deploys back to iOS 17?

level: principalimportance: should knowfreq 40%

basics

~20 s

Let system controls carry Liquid Glass, which standard SwiftUI components already use, and keep glassEffect to a short list of custom floating controls behind #available with a Material fallback. Check every custom surface for legibility and under accessibility settings.

open as a page

In SwiftUI, how do symbolEffect(_:options:value:) and symbolEffect(_:options:isActive:) differ, and how do you animate a favourite heart filling in?

level: middleimportance: nice to knowfreq 32%

basics

~10 s

symbolEffect(:options:value:) plays a discrete effect such as bounce once each time an Equatable value changes; symbolEffect(:options:isActive:) runs an indefinite effect such as pulse while a Boolean is true. A heart filling in uses contentTransition(.symbolEffect(.replace)).

open as a page

In SwiftUI on iOS 17 and later, how do colorEffect, distortionEffect and layerEffect apply a Metal shader, and why does layerEffect need maxSampleOffset?

level: seniorimportance: nice to knowfreq 25%

basics

~20 s

Each modifier runs a [[ stitchable ]] Metal function from a ShaderLibrary per pixel: colorEffect recolours one pixel, distortionEffect returns where to read from, layerEffect samples the rasterized view freely. maxSampleOffset declares how far reads may stray from each pixel.

open as a page