Skip to content

Instantly share code, notes, and snippets.

@martinlexow
Created August 1, 2021 16:41
Show Gist options
  • Save martinlexow/e46d5fa9153977f1930f1095904d657a to your computer and use it in GitHub Desktop.
Save martinlexow/e46d5fa9153977f1930f1095904d657a to your computer and use it in GitHub Desktop.
import SwiftUI
import PlaygroundSupport
struct CustomTabButton: View {
init(_ caption: LocalizedStringKey, systemImage: String) {
self.caption = caption
self.systemImage = systemImage
}
let caption: LocalizedStringKey
let systemImage: String
@ScaledMetric(relativeTo: .body) private var relativeImageHeight: CGFloat = 38.0
var body: some View {
return Button(action: {
// do something here
}, label: {
VStack(spacing: .zero) {
VStack(spacing: .zero) {
Spacer()
Image(systemName: self.systemImage)
.imageScale(.large)
Spacer()
}
.frame(height: self.relativeImageHeight)
.background(Color.green.opacity(0.3))
Text(self.caption)
.font(Font.caption.weight(.semibold))
}
})
.buttonStyle(PlainButtonStyle())
.padding(12.0)
.background(Color.blue.opacity(0.2))
}
}
struct CustomTabBar: View {
var body: some View {
HStack(alignment: .center, spacing: .zero) {
Spacer()
CustomTabButton("recent", systemImage: "calendar.badge.clock")
Spacer()
CustomTabButton("browse", systemImage: "square.grid.2x2.fill")
Spacer()
CustomTabButton("settings", systemImage: "gearshape.2.fill")
Spacer()
}
.background(Color.black.opacity(0.1).cornerRadius(16.0))
.frame(width: 420.0, height: 200.0)
.padding(24.0)
}
}
// Preview
PlaygroundPage.current.setLiveView(CustomTabBar())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment