Skip to content

Instantly share code, notes, and snippets.

@schevgeny
Created October 12, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schevgeny/e238db9eabc5aade97a3841166aa3b90 to your computer and use it in GitHub Desktop.
Save schevgeny/e238db9eabc5aade97a3841166aa3b90 to your computer and use it in GitHub Desktop.
How to create Tab Bar and Notification icon by using SwiftUI.
@State var selectedView = 0
var position: CGFloat = 2
var nTab: CGFloat = 4
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .bottomLeading) {
TabView(selection: self.$selectedView) {
HomeView()
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}.tag(0)
ListView()
.tabItem {
Image(systemName: "list.bullet")
Text("List")
}.tag(1)
OrderView()
.tabItem {
Image(systemName: "bag.fill")
Text("Ordered")
}.tag(2)
SettingsView()
.tabItem {
Image(systemName: "gear")
Text("Settings")
}.tag(3)
}
ZStack {
Rectangle()
.foregroundColor(.red)
.cornerRadius(8)
Text("5")
.foregroundColor(.white)
.font(Font.system(size: 12))
}
.frame(width: 16, height: 16)
.offset(x: ( ( 2.0 * position) - 0.95 ) * (geometry.size.width / ( 2.0 * nTab )) + 2.0, y: -30)
.opacity(1.0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment