Basics
Button
Triggers an action when the user taps it. Accepts any view as its label — text, image, or a combination of both. Supports multiple visual styles with `.buttonStyle()`.
iOS Preview
Basic code
Button("Guardar cambios") {
guardarCambios()
}
// Con icono
Button {
eliminar()
} label: {
Label("Eliminar", systemImage: "trash")
}
.buttonStyle(.borderedProminent)
.tint(.red) Common modifiers
.buttonStyle()
Visual style: `.bordered`, `.borderedProminent`, `.plain`
.disabled()
Disables interaction when `true`
.tint()
Button color and highlight tint
.controlSize()
Size: `.mini`, `.small`, `.regular`, `.large`
Basics
Text
Displays one or more lines of static text. Supports inline Markdown, string interpolation, and date/number formatting. It's the most basic display view in SwiftUI.
iOS Preview
Título grande
Título 2
Texto cuerpo normal
Texto secundario
Pie de foto / caption
Basic code
Text("Hola, mundo")
.font(.title)
.fontWeight(.bold)
// Con Markdown
Text("Texto en **negrita** y *cursiva*")
// Con formato de número
Text(precio, format: .currency(code: "MXN")) Common modifiers
.font()
Font: `.title`, `.body`, `.caption`, `.system(size:)`
.fontWeight()
Weight: `.bold`, `.semibold`, `.light`
.foregroundStyle()
Text color
.lineLimit()
Max number of lines (nil = unlimited)
Basics
Image
Displays images from the asset catalog, SF Symbols, or remote URLs (with `AsyncImage`). Maintains the original aspect ratio by default. Can be scaled and cropped with modifiers.
iOS Preview
👤
★★★★★
🏔
Basic code
// SF Symbol
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
// Asset catalog
Image("avatar")
.resizable()
.scaledToFill()
.frame(width: 80, height: 80)
.clipShape(Circle()) Common modifiers
.resizable()
Allows the image to be resized
.scaledToFit()
Scales while keeping aspect ratio within frame
.scaledToFill()
Fills the frame, cropping if necessary
.clipShape()
Clips to a shape: `Circle()`, `RoundedRectangle()`
Basics
Label
Combines an icon and text in a standard layout. Accepts SF Symbols or asset catalog images. Many SwiftUI components like `List` and `Menu` automatically leverage the `Label` layout.
iOS Preview
❤️Favoritos
📤Compartir
⚙️Ajustes
🗑Eliminar
Basic code
Label("Favoritos", systemImage: "heart.fill")
Label("Compartir", systemImage: "square.and.arrow.up")
.foregroundStyle(.blue)
// Solo ícono
Label("Ajustes", systemImage: "gear")
.labelStyle(.iconOnly) Common modifiers
.labelStyle()
`.iconOnly`, `.titleOnly`, `.titleAndIcon` (default)
.foregroundStyle()
Color for icon and text
.font()
Font size and weight
.imageScale()
Icon scale: `.small`, `.medium`, `.large`
Basics
Link
Opens a URL in Safari or the associated app when tapped. Accepts any view as its label, not just text. It's the SwiftUI equivalent of a hyperlink.
iOS Preview
Visitar slekens.dev
Política de privacidad
🧭
Abrir en Safari
Basic code
Link("Visitar slekens.dev",
destination: URL(string: "https://slekens.dev")!)
// Con vista personalizada como label
Link(destination: URL(string: "https://slekens.dev")!) {
HStack {
Image(systemName: "safari")
Text("Abrir en Safari")
}
} Common modifiers
.foregroundStyle()
Link color (default: system accent)
.font()
Font size and weight
.underline()
Shows or hides the underline
.tint()
Tint color inherited by content
Input
TextField
An editable single-line text field. Requires a `@State` binding for its value. Shows the appropriate keyboard based on the configured content type.
iOS Preview
Abraham
Email
Nombre del proyecto
Basic code
@State private var nombre = ""
TextField("Nombre", text: $nombre)
.textFieldStyle(.roundedBorder)
.keyboardType(.default)
// Con label personalizado
TextField(text: $email) {
Label("Email", systemImage: "envelope")
} Common modifiers
.textFieldStyle()
Visual style: `.roundedBorder`, `.plain`
.keyboardType()
Keyboard type: `.emailAddress`, `.numberPad`, `.URL`
.autocorrectionDisabled()
Disables autocorrection
.focused()
Controls field focus with a `FocusState`
Input
SecureField
A text field that masks its content with dots as the user types. Ideal for passwords and sensitive data. Works exactly like `TextField` but with masked input.
iOS Preview
Contraseña
••••••••
Basic code
@State private var password = ""
SecureField("Contraseña", text: $password)
.textFieldStyle(.roundedBorder)
.submitLabel(.done)
.onSubmit {
iniciarSesion()
} Common modifiers
.textFieldStyle()
Visual style of the field
.focused()
Controls focus with a `FocusState`
.submitLabel()
Return button label: `.done`, `.go`, `.next`
.onSubmit()
Action when Return is pressed
Input
Toggle
A Boolean switch that alternates between on and off. Requires a binding to a `Bool`. On iOS it renders as the characteristic green system switch.
iOS Preview
Notificaciones
Modo oscuro
Basic code
@State private var notificaciones = true
Toggle("Notificaciones", isOn: $notificaciones)
// Estilo botón
Toggle("Wi-Fi", isOn: $wifi)
.toggleStyle(.button)
.tint(.blue) Common modifiers
.toggleStyle()
Style: `.switch` (default), `.button`, `.checkbox`
.tint()
Color when active (default: system green)
.disabled()
Disables interaction
.labelsHidden()
Hides the text label, shows only the switch
Input
Slider
A continuous value selector within a range. The user drags the thumb to select a value. Can be configured with discrete steps using the `step` parameter.
iOS Preview
🔇
🔊
☀️
☀️
Basic code
@State private var volumen: Double = 0.5
Slider(value: $volumen, in: 0...1)
// Con rango y step
Slider(value: $brillo, in: 0...100, step: 10) {
Text("Brillo")
} minimumValueLabel: {
Image(systemName: "sun.min")
} maximumValueLabel: {
Image(systemName: "sun.max")
} Common modifiers
.tint()
Color of the active track (left of thumb)
.disabled()
Disables interaction
.onChange(of:)
Executes code whenever the value changes
.accentColor()
Accent color (legacy alternative to `.tint()`)
Input
Stepper
Increments or decrements a value with + and − buttons. Accepts a range and an optional step. Useful for small quantities where the user needs precise control.
iOS Preview
Cantidad: 3
Precio: $150
Basic code
@State private var cantidad = 1
Stepper("Cantidad: \(cantidad)", value: $cantidad, in: 1...10)
// Con paso personalizado
Stepper(value: $precio, in: 0...1000, step: 50) {
Text("Precio: $\(precio)")
} Common modifiers
.disabled()
Disables both buttons
.onIncrement()
Custom action on increment (without binding)
.onDecrement()
Custom action on decrement (without binding)
.font()
Label font
Input
Picker
A selector for choosing one option from several. Supports multiple styles: segmented, wheel, menu, and more. Options must be `Hashable`. The style completely changes the look.
iOS Preview
Swift
Kotlin
Dart
Categoría
iOS›
Basic code
@State private var seleccion = "Swift"
let opciones = ["Swift", "Kotlin", "Dart"]
Picker("Lenguaje", selection: $seleccion) {
ForEach(opciones, id: \.self) {
Text($0)
}
}
.pickerStyle(.segmented) Common modifiers
.pickerStyle()
`.segmented`, `.wheel`, `.menu`, `.inline`, `.navigationLink`
.tint()
Color of the active selection
.disabled()
Disables interaction
.labelsHidden()
Hides the picker label
Input
DatePicker
A date and/or time selector. Can be restricted to show only date, only time, or both with the `displayedComponents` parameter. Supports valid date range.
iOS Preview
Fecha de entrega
may 21, 2026
Hora
9:00 AM
Basic code
@State private var fecha = Date()
DatePicker("Fecha de entrega", selection: $fecha,
in: Date()...,
displayedComponents: .date)
.datePickerStyle(.compact)
// Solo hora
DatePicker("Hora", selection: $hora,
displayedComponents: .hourAndMinute) Common modifiers
.datePickerStyle()
`.compact`, `.graphical`, `.wheel`
.disabled()
Disables selection
in:
Allowed date range: `Date()...` for future dates
displayedComponents:
`.date`, `.hourAndMinute`, or both
Layout
HStack
Stacks its child views horizontally, left to right. Spacing between elements is controlled with `spacing`. Vertical alignment is controlled with `alignment`.
iOS Preview
👤
Abraham
iOS Developer
›
Seguir
Mensaje
Compartir
Basic code
HStack(spacing: 16) {
Image(systemName: "person.circle")
.font(.largeTitle)
VStack(alignment: .leading) {
Text("Abraham")
.font(.headline)
Text("iOS Developer")
.foregroundStyle(.secondary)
}
Spacer()
}
.padding() Common modifiers
alignment:
Vertical alignment: `.top`, `.center`, `.bottom`, `.firstTextBaseline`
spacing:
Points between elements (default: 8)
.frame()
Width and height of the stack
.padding()
Inner padding around the stack
Layout
VStack
Stacks its child views vertically, top to bottom. It's the most common container in SwiftUI. Horizontal alignment is controlled with `alignment`.
iOS Preview
Pokédex
151 Pokémon de Kanto
🔴
#001 Bulbasaur
Planta / Veneno
🔥
#004 Charmander
Fuego
Basic code
VStack(alignment: .leading, spacing: 12) {
Text("Pokédex")
.font(.largeTitle)
.fontWeight(.bold)
Text("151 Pokémon de Kanto")
.foregroundStyle(.secondary)
Divider()
ForEach(pokemones) { p in
PokemonRow(pokemon: p)
}
}
.padding() Common modifiers
alignment:
Horizontal alignment: `.leading`, `.center`, `.trailing`
spacing:
Points between elements (default: 8)
.frame()
Width and height of the stack
.padding()
Inner padding
Layout
ZStack
Overlays its child views on the Z axis, back to front. Each view is centered over the previous ones by default. Ideal for overlays, badges, and layering effects.
iOS Preview
🎮
3
👤
Basic code
ZStack(alignment: .topTrailing) {
AsyncImage(url: portadaURL)
.frame(width: 200, height: 200)
.clipShape(RoundedRectangle(cornerRadius: 16))
// Badge encima
Text("3")
.font(.caption2).fontWeight(.bold)
.foregroundStyle(.white)
.padding(6)
.background(.red)
.clipShape(Circle())
.offset(x: 8, y: -8)
} Common modifiers
alignment:
Anchor point for stacking: `.topLeading`, `.bottomTrailing`, etc.
.zIndex()
Controls the Z order of a specific child
.frame()
Fixes the ZStack size
.clipped()
Clips content to ZStack bounds
Layout
Spacer
Occupies all available space on the primary axis of the enclosing stack. In an `HStack` it expands horizontally, in a `VStack` vertically. Pushes remaining views apart.
iOS Preview
Título de secciónEditar
☁️iCloudActivo›
Basic code
// Empuja el botón al lado derecho
HStack {
Text("Título")
.font(.headline)
Spacer()
Button("Editar") { }
}
// Centra el contenido verticalmente
VStack {
Spacer()
Text("Centrado")
Spacer()
} Common modifiers
minLength:
Guaranteed minimum space (default: 8)
.frame()
Can set a maximum size
(no visible modifier)
Spacer has no visual appearance on its own
.hidden()
Hides but preserves the space
Layout
Divider
A horizontal (in VStack) or vertical (in HStack) line that visually separates content. Adapts its orientation to the containing stack automatically.
iOS Preview
Perfil
Notificaciones
Privacidad
Basic code
VStack {
Text("Sección 1")
Divider()
Text("Sección 2")
}
// Personalizado
Divider()
.overlay(Color.blue.opacity(0.4))
.padding(.horizontal) Common modifiers
.overlay()
Changes the line color
.padding()
Adds space around the divider
.frame()
Limits the width or height of the line
(no own modifiers)
Use `.overlay` to customize color
Layout
ScrollView
Makes its content scrollable on the specified axis. Scrolls vertically by default. Can be combined with `LazyVStack` or `LazyHStack` for performance-optimized lists.
iOS Preview
Basic code
ScrollView {
LazyVStack(spacing: 12) {
ForEach(items) { item in
ItemRow(item: item)
}
}
.padding()
}
// Horizontal
ScrollView(.horizontal, showsIndicators: false) {
HStack { ... }
} Common modifiers
.scrollIndicators()
Show/hide scroll bar: `.hidden`, `.visible`
.scrollDisabled()
Disables scroll programmatically
.scrollTargetBehavior()
Snap between elements: `.viewAligned`, `.paging`
.contentMargins()
Scrollable content margins
Containers
List
A scroll-optimized container for displaying rows of data. Supports sections, swipe actions, pull-to-refresh, and selection. It's iOS's native way to show lists.
iOS Preview
Basic code
List(pokemones) { pokemon in
HStack {
AsyncImage(url: pokemon.imageURL)
.frame(width: 44, height: 44)
VStack(alignment: .leading) {
Text(pokemon.nombre)
Text(pokemon.tipo)
.foregroundStyle(.secondary)
}
}
.swipeActions {
Button("Favorito", systemImage: "heart") {
toggleFavorito(pokemon)
}.tint(.pink)
}
}
.listStyle(.insetGrouped) Common modifiers
.listStyle()
`.insetGrouped`, `.grouped`, `.plain`, `.sidebar`
.swipeActions()
Left/right swipe actions per row
.refreshable()
Adds pull-to-refresh with async/await
.listRowSeparator()
Shows or hides row separator
Containers
Form
A container for inputs and controls with native iOS form styling. Groups automatically in visual sections. Pickers, toggles, and textfields adapt to the Form context.
iOS Preview
Basic code
Form {
Section("Perfil") {
TextField("Nombre", text: $nombre)
TextField("Email", text: $email)
}
Section("Preferencias") {
Toggle("Notificaciones", isOn: $notifs)
Picker("Tema", selection: $tema) {
Text("Claro").tag("light")
Text("Oscuro").tag("dark")
}
}
Section {
Button("Guardar", action: guardar)
.frame(maxWidth: .infinity)
}
} Common modifiers
.formStyle()
`.automatic`, `.grouped`, `.columns`
.scrollDisabled()
Disables form scrolling
Section(header:footer:)
Groups rows with optional header and footer
.disabled()
Disables all form controls
Containers
Group
A logical container that groups views without affecting layout. Useful for applying the same modifier to multiple children at once, or to surpass the 10-view ViewBuilder limit.
iOS Preview
Metadatos (Group)
Versión: 1.2.0
Build: 42
iOS mínimo: 17.0
Autor: slekens
Basic code
// Aplicar modificador a varios elementos
Group {
Text("Línea 1")
Text("Línea 2")
Text("Línea 3")
}
.font(.caption)
.foregroundStyle(.secondary)
// Superar límite de 10 vistas en ViewBuilder
VStack {
Group {
// vistas 1–9
}
Group {
// vistas 10–18
}
} Common modifiers
.font()
Applies font to all group children
.foregroundStyle()
Color applied to all children
.opacity()
Opacity applied to all children
.disabled()
Disables all children
Containers
Section
Groups content inside `List` or `Form` with an optional header and/or footer. Renders with native styling based on context — inset in `Form`, plain in `List`.
iOS Preview
Basic code
List {
Section {
Text("Elemento 1")
Text("Elemento 2")
} header: {
Text("Mi sección")
} footer: {
Text("Texto explicativo al pie")
.font(.caption)
}
} Common modifiers
header:
View shown as section header
footer:
View shown as section footer
.defaultScrollAnchor()
Initial scroll anchor for the section
(no own modifiers)
Section inherits style from parent container
Navigation
TabView
Displays multiple views with a tab bar at the bottom. Each tab is defined with `.tabItem`. Supports numeric and text badges. Can also be used as a horizontal pager.
iOS Preview
Basic code
TabView {
PokemonListView()
.tabItem {
Label("Pokédex", systemImage: "list.bullet")
}
FavoritosView()
.tabItem {
Label("Favoritos", systemImage: "heart.fill")
}
.badge(3)
AjustesView()
.tabItem {
Label("Ajustes", systemImage: "gear")
}
} Common modifiers
.tabItem()
Defines icon and text for each tab (applied to child)
.badge()
Numeric or text badge on the tab icon
.tabViewStyle()
`.automatic`, `.page` (horizontal pager)
selection:
Binding to control active tab programmatically