Skip to content

Instantly share code, notes, and snippets.

@benguild
Created February 28, 2025 07:31
Show Gist options
  • Save benguild/cc6a4627bc58dd96c0b97a24569a7a67 to your computer and use it in GitHub Desktop.
Save benguild/cc6a4627bc58dd96c0b97a24569a7a67 to your computer and use it in GitHub Desktop.
This seems like a fairly accurate (yet incomplete) "backport" of `ContentUnavailableView` from iOS 17 to iOS 16.
import SwiftUI
@available(iOS 16, *)
struct ContentUnavailableView<Label: View, Description: View>: View {
private struct VerticalLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
VStack(spacing: -1) {
configuration.icon
.font(.system(size: 48))
.foregroundColor(.secondary)
.padding(.bottom)
configuration.title
.font(.system(.title2, weight: .bold))
}
.multilineTextAlignment(.center)
}
}
var label: () -> Label
var description: () -> Description
var body: some View {
VStack(spacing: 3) {
label()
.labelStyle(VerticalLabelStyle())
description()
.font(.subheadline)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
}
.padding()
.padding(.bottom)
.padding(.bottom, 4)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
#Preview {
ContentUnavailableView {
Label("No Mail", systemImage: "tray.fill")
} description: {
Text("New mails you receive will appear here.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment