Created
October 23, 2025 09:03
-
-
Save dterekhov/4e54ce82b37c07d2895c5ee8e8773de1 to your computer and use it in GitHub Desktop.
Be able to scroll content under the bottom bar with safeAreaInset modifier #swiftui #tip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct GradientBuilderView: View { | |
| @State private var gradientName = "New Gradient" | |
| @State private var stopCount = 7 | |
| @State private var isEditing = false | |
| var body: some View { | |
| ScrollView { | |
| VStack(spacing: 20) { | |
| ForEach(0..<stopCount, id: \.self) { index in | |
| RoundedRectangle(cornerRadius: 8) | |
| .fill(Color(hue: Double(index) / Double(stopCount), saturation: 1, brightness: 1)) | |
| .frame(height: 44) | |
| .padding(.horizontal) | |
| } | |
| } | |
| .padding(.top) | |
| } | |
| // Allow content to scroll beneath bottom bar | |
| .safeAreaInset(edge: .bottom) { | |
| HStack { | |
| if isEditing { | |
| TextField("Name", text: $gradientName) | |
| .textFieldStyle(.roundedBorder) | |
| .padding(.horizontal) | |
| } else { | |
| Text(gradientName.isEmpty ? "Untitled Gradient" : gradientName) | |
| .font(.headline) | |
| .foregroundStyle(.primary) | |
| .padding(.horizontal) | |
| } | |
| Spacer() | |
| Text("\(stopCount) colors") | |
| .foregroundStyle(.secondary) | |
| } | |
| .padding() | |
| .background(.thinMaterial) | |
| } | |
| .toolbar { | |
| ToolbarItem(placement: .topBarTrailing) { | |
| Button(isEditing ? "Done" : "Edit") { | |
| isEditing.toggle() | |
| } | |
| } | |
| } | |
| } | |
| } | |
| // MARK: - Preview | |
| #Preview { | |
| NavigationStack { | |
| GradientBuilderView() | |
| .navigationTitle("Gradients") | |
| } | |
| } |
Author
dterekhov
commented
Oct 23, 2025

Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

