Skip to content

Instantly share code, notes, and snippets.

@dterekhov
Created October 23, 2025 09:03
Show Gist options
  • Select an option

  • Save dterekhov/4e54ce82b37c07d2895c5ee8e8773de1 to your computer and use it in GitHub Desktop.

Select an option

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
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")
}
}
@dterekhov
Copy link
Author

4EDFAEC9-5E92-4528-8714-1EBAF1897F25_1_105_c

@dterekhov
Copy link
Author

5917C56B-CE77-4263-8254-C30C50A74C10_1_105_c

@dterekhov
Copy link
Author

487B6884-762E-426B-8306-F64F6666443D_1_105_c

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