Created
October 12, 2022 20:52
-
-
Save schevgeny/e238db9eabc5aade97a3841166aa3b90 to your computer and use it in GitHub Desktop.
How to create Tab Bar and Notification icon by using SwiftUI.
This file contains 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
@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