Barra de herramientas y título de navegación
Añada títulos y botones de barra de herramientas a las barras.
Barra de herramientas y título de navegación es una lección gratuita de SwiftUI Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de SwiftUI Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de SwiftUI Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Naming the Screen
Every screen deserves a clear name. The navigationTitle modifier puts a heading in the navigation bar so users always know where they are. 🧭
.navigationTitle("Inbox")Where the Title Goes
Attach navigationTitle to the content inside the NavigationStack, not to the stack itself. The bar then reads the title from the current screen.
NavigationStack {
List { }
.navigationTitle("Inbox")
}Large vs Inline
By default the title is large and shrinks as you scroll. Use navigationBarTitleDisplayMode to force a compact inline style instead.
.navigationBarTitleDisplayMode(.inline)Adding Toolbar Buttons
The toolbar modifier lets you place buttons in the navigation bar, like an add button or an edit action for the current screen.
.toolbar {
Button("Add") { addItem() }
}Choosing a Placement
Wrap each control in a ToolbarItem and pick a placement so buttons land on the correct side of the bar.
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Add") { }
}
}Leading and Trailing
Use topBarLeading for the left edge and topBarTrailing for the right. These adapt automatically for right-to-left languages. 🌍
Icons in the Bar
Toolbar buttons often use SF Symbols instead of words to stay compact. A small image keeps the bar tidy on every device.
Button {
addItem()
} label: {
Image(systemName: "plus")
}Many Buttons at Once
You can add several ToolbarItem entries in one toolbar block, grouping related actions like edit, share, and add together.
The Bottom Toolbar
Placement is not limited to the top. Use bottomBar to pin actions to the bottom of the screen for thumb-friendly controls.
ToolbarItem(placement: .bottomBar) {
Button("Done") { }
}Titles Follow the Stack
Each pushed screen sets its own title, and the bar updates as you navigate. The previous title even becomes the back button label.
Keep Bars Uncluttered
Resist filling the bar with buttons. Two or three clear actions keep the screen calm and easy to scan.
Quick Check
Which modifier adds buttons to the navigation bar?
Recap: Toolbar & Title
You name screens with navigationTitle and add buttons with toolbar and ToolbarItem placements. Up next, driving navigation entirely from code. 🚀
Preguntas frecuentes
¿La lección «Barra de herramientas y título de navegación» es gratis?
Sí — el texto completo de «Barra de herramientas y título de navegación» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de SwiftUI Academy, actualiza a CoddyKit PRO. El curso de SwiftUI Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Barra de herramientas y título de navegación»?
Añada títulos y botones de barra de herramientas a las barras. Practicas SwiftUI Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar SwiftUI Academy?
No se requiere experiencia previa. SwiftUI Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.
¿Cuánto tiempo toma la lección «Barra de herramientas y título de navegación»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de SwiftUI Academy?
Sí. Cada lección de SwiftUI Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Navegación a pantallas con NavigationLink
- Pasar datos a vistas de detalles
- Barra de herramientas y título de navegación
- Rutas de navegación programática