Loading...
Loading...
Compare original and translation side by side
What toolbar feature do you need?
|
+- User-customizable toolbar (add/remove/reorder items)
| +- Use .toolbar(id:) with ToolbarItem(id:)
|
+- Search field in toolbar
| +- Minimize to button -> .searchToolbarBehavior(.minimize)
| +- Reposition search -> DefaultToolbarItem(kind: .search, placement:)
|
+- Toolbar transition/animation
| +- Zoom transition from toolbar item -> .matchedTransitionSource(id:in:)
| +- Hide glass background -> .sharedBackgroundVisibility(.hidden)
|
+- Custom subtitle area content
| +- Use ToolbarItem(placement: .largeSubtitle)
|
+- System toolbar items with custom placement
| +- DefaultToolbarItem(kind: .search/.sidebar, placement:)What toolbar feature do you need?
|
+- User-customizable toolbar (add/remove/reorder items)
| +- Use .toolbar(id:) with ToolbarItem(id:)
|
+- Search field in toolbar
| +- Minimize to button -> .searchToolbarBehavior(.minimize)
| +- Reposition search -> DefaultToolbarItem(kind: .search, placement:)
|
+- Toolbar transition/animation
| +- Zoom transition from toolbar item -> .matchedTransitionSource(id:in:)
| +- Hide glass background -> .sharedBackgroundVisibility(.hidden)
|
+- Custom subtitle area content
| +- Use ToolbarItem(placement: .largeSubtitle)
|
+- System toolbar items with custom placement
| +- DefaultToolbarItem(kind: .search/.sidebar, placement:)| API | Minimum Version | Notes |
|---|---|---|
| iOS 14 | Basic toolbar |
| iOS 14 | Standard placements |
| iOS 16 | Customizable toolbars |
| iOS 16 | Items in customizable toolbars |
| iOS 16 | Fixed and flexible spacers |
| iOS 15 | Search integration |
| iOS 17 | Minimized search button |
| iOS 18 | Reposition system items |
| iOS 18 | Subtitle area content |
| iOS 18 | Toolbar transition source |
| iOS 18 | Glass background control |
| API | 最低版本 | 说明 |
|---|---|---|
| iOS 14 | 基础工具栏 |
| iOS 14 | 标准布局位置 |
| iOS 16 | 可自定义工具栏 |
| iOS 16 | 可自定义工具栏中的项 |
| iOS 16 | 固定和灵活间距控件 |
| iOS 15 | 搜索集成 |
| iOS 17 | 最小化搜索按钮 |
| iOS 18 | 重新调整系统项位置 |
| iOS 18 | 副标题区域内容 |
| iOS 18 | 工具栏过渡源 |
| iOS 18 | 毛玻璃背景控制 |
ContentView()
.toolbar(id: "main-toolbar") {
ToolbarItem(id: "tag") {
TagButton()
}
ToolbarItem(id: "share") {
ShareButton()
}
ToolbarSpacer(.fixed)
ToolbarItem(id: "more") {
MoreButton()
}
}ContentView()
.toolbar(id: "main-toolbar") {
ToolbarItem(id: "tag") {
TagButton()
}
ToolbarItem(id: "share") {
ShareButton()
}
ToolbarSpacer(.fixed)
ToolbarItem(id: "more") {
MoreButton()
}
}ToolbarSpacer(.fixed) // Fixed-width space
ToolbarSpacer(.flexible) // Flexible space — pushes items apartToolbarSpacer(.fixed) // 固定宽度的间距
ToolbarSpacer(.flexible) // 灵活间距——将项分开// ❌ Missing IDs in customizable toolbar — items can't be customized
.toolbar(id: "main") {
ToolbarItem { // No id parameter
ShareButton()
}
}
// ✅ Every item needs its own ID
.toolbar(id: "main") {
ToolbarItem(id: "share") {
ShareButton()
}
}// ❌ 可自定义工具栏中缺少ID——项无法被定制
.toolbar(id: "main") {
ToolbarItem { // 缺少id参数
ShareButton()
}
}
// ✅ 每个项都需要有自己的ID
.toolbar(id: "main") {
ToolbarItem(id: "share") {
ShareButton()
}
}@State private var searchText = ""
NavigationStack {
RecipeList()
.searchable(text: $searchText)
.searchToolbarBehavior(.minimize)
}@State private var searchText = ""
NavigationStack {
RecipeList()
.searchable(text: $searchText)
.searchToolbarBehavior(.minimize)
}NavigationSplitView {
AllCalendarsView()
} detail: {
SelectedCalendarView()
.searchable(text: $query)
.toolbar {
ToolbarItem(placement: .bottomBar) {
CalendarPicker()
}
ToolbarItem(placement: .bottomBar) {
Invites()
}
DefaultToolbarItem(kind: .search, placement: .bottomBar)
ToolbarSpacer(placement: .bottomBar)
ToolbarItem(placement: .bottomBar) {
NewEventButton()
}
}
}NavigationSplitView {
AllCalendarsView()
} detail: {
SelectedCalendarView()
.searchable(text: $query)
.toolbar {
ToolbarItem(placement: .bottomBar) {
CalendarPicker()
}
ToolbarItem(placement: .bottomBar) {
Invites()
}
DefaultToolbarItem(kind: .search, placement: .bottomBar)
ToolbarSpacer(placement: .bottomBar)
ToolbarItem(placement: .bottomBar) {
NewEventButton()
}
}
}.toolbar {
DefaultToolbarItem(kind: .search, placement: .bottomBar)
DefaultToolbarItem(kind: .sidebar, placement: .navigationBarLeading)
}.toolbar {
DefaultToolbarItem(kind: .search, placement: .bottomBar)
DefaultToolbarItem(kind: .sidebar, placement: .navigationBarLeading)
}NavigationStack {
DetailView()
.navigationTitle("Title")
.navigationSubtitle("Subtitle")
.toolbar {
ToolbarItem(placement: .largeSubtitle) {
CustomLargeNavigationSubtitle()
}
}
}.largeSubtitlenavigationSubtitle(_:)NavigationStack {
DetailView()
.navigationTitle("Title")
.navigationSubtitle("Subtitle")
.toolbar {
ToolbarItem(placement: .largeSubtitle) {
CustomLargeNavigationSubtitle()
}
}
}.largeSubtitlenavigationSubtitle(_:)struct ContentView: View {
@State private var isPresented = false
@Namespace private var namespace
var body: some View {
NavigationStack {
DetailView()
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Show Sheet", systemImage: "globe") {
isPresented = true
}
}
.matchedTransitionSource(id: "world", in: namespace)
}
.sheet(isPresented: $isPresented) {
SheetView()
.navigationTransition(
.zoom(sourceID: "world", in: namespace))
}
}
}
}struct ContentView: View {
@State private var isPresented = false
@Namespace private var namespace
var body: some View {
NavigationStack {
DetailView()
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Show Sheet", systemImage: "globe") {
isPresented = true
}
}
.matchedTransitionSource(id: "world", in: namespace)
}
.sheet(isPresented: $isPresented) {
SheetView()
.navigationTransition(
.zoom(sourceID: "world", in: namespace))
}
}
}
}ContentView()
.toolbar(id: "main") {
ToolbarItem(id: "build-status", placement: .principal) {
BuildStatus()
}
.sharedBackgroundVisibility(.hidden)
}ContentView()
.toolbar(id: "main") {
ToolbarItem(id: "build-status", placement: .principal) {
BuildStatus()
}
.sharedBackgroundVisibility(.hidden)
}| # | Mistake | Fix |
|---|---|---|
| 1 | Missing | Every item in |
| 2 | Using | Must pair with |
| 3 | Putting | Apply |
| 4 | Using | |
| 5 | Forgetting | Without explicit placement, system items use their default position |
| # | 错误 | 修复方案 |
|---|---|---|
| 1 | 可自定义工具栏中的ToolbarItem缺少id | 可自定义工具栏中的每个 |
| 2 | 在未使用 | 必须与 |
| 3 | 将 | 将 |
| 4 | 同时使用 | |
| 5 | DefaultToolbarItem遗漏 | 如果不明确指定布局位置,系统项会使用默认位置 |
| Platform | Recommendations |
|---|---|
| iOS | Bottom bar useful on iPhones. Use |
| iPadOS | Customizable toolbars valuable in productivity apps. Consider keyboard shortcuts. |
| macOS | Users expect toolbar customization. Use spacers for logical groupings. |
| 平台 | 建议 |
|---|---|
| iOS | 底部工具栏在iPhone上很实用。使用 |
| iPadOS | 可自定义工具栏在生产力应用中很有价值。考虑添加键盘快捷键。 |
| macOS | 用户期望工具栏可自定义。使用间距控件进行逻辑分组。 |
.toolbar(id:)ToolbarItemid.toolbar(id:)ToolbarItemid.searchable().searchToolbarBehavior()DefaultToolbarItem(kind: .search).searchable().searchToolbarBehavior()DefaultToolbarItem(kind: .search).matchedTransitionSourceToolbarItem@Namespace.matchedTransitionSource.navigationTransition(.zoom).matchedTransitionSourceToolbarItem@Namespace.matchedTransitionSource.navigationTransition(.zoom)