2023 SwiftUI & UI Frameworks
WWDC23 · 14 min · SwiftUI & UI Frameworks
Update your app for watchOS 10
Join us as we update an Apple Watch app to take advantage of the latest features in watchOS 10. In this code-along, we’ll show you how to use the latest SwiftUI APIs to maximize glanceability and reorient app navigation around the Digital Crown.
Watch at developer.apple.com ↗Chapters
Code shown on screen · 8 snippets
NavigationSplitView
NavigationSplitView {
List(backyardsData.backyards, selection: $selectedBackyard) { backyard in
BackyardCell(backyard: backyard)
}
.listStyle(.carousel)
} detail: {
if let selectedBackyard {
BackyardView(backyard: selectedBackyard)
} else {
BackyardUnavailableView()
}
} Vertical TabView
TabView {
TodayView()
.navigationTitle("Today")
HabitatGaugeView(level: $waterLevel, habitatType: .water, tintColor: .blue)
.navigationTitle("Water")
HabitatGaugeView(level: $foodLevel, habitatType: .food, tintColor: .green)
.navigationTitle("Food")
List {
VisitorView()
.navigationTitle("Visitors")
}
}
.tabViewStyle(.verticalPage) Add refill button to Toolbar
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
Spacer()
Button {
level = Int(min(100, Double(level) + 5))
} label: {
Label("Add", systemImage: "plus")
}
}
} HabitatGaugeView background color function and variables
func backgroundColor(_ level: Int, for type: HabitatType) -> Color {
let color: Color = type == .food ? .green : .blue
return level < 40 ? .red : color
}
var waterColor: Color {
backgroundColor(waterLevel, for: .water)
}
var foodColor: Color {
backgroundColor(foodLevel, for: .food)
} .containerBackground within TabView
TabView {
TodayView()
.navigationTitle("Today")
.containerBackground(Color.accentColor.gradient, for: .tabView)
HabitatGaugeView(level: $waterLevel, habitatType: .water, tintColor: waterColor)
.navigationTitle("Water")
.containerBackground(waterColor.gradient, for: .tabView)
HabitatGaugeView(level: $foodLevel, habitatType: .food, tintColor: foodColor)
.navigationTitle("Food")
.containerBackground(foodColor.gradient, for: .tabView)
List {
VisitorView()
.navigationTitle("Visitors")
.containerBackground(Color.accentColor.gradient, for: .tabView)
}
}
.tabViewStyle(.verticalPage)
.environmentObject(backyard)
.navigationTitle(backyard.displayName) Add material to the backyard name
.foregroundStyle(.secondary)
.background(Material.ultraThin, in: RoundedRectangle(cornerRadius: 7)) Visitor score overlay with materials
.overlay(alignment: .topTrailing) {
Text("\(backyard.visitorScore)")
.frame(width: 25, height: 25)
.foregroundStyle(.secondary)
.background(.ultraThinMaterial, in: .circle)
.padding(.top, 5)
} Light materials
.environment(\.colorScheme, .light) Resources
Related sessions
-
10 min -
19 min