Created
January 24, 2024 12:48
-
-
Save Tprezioso/12d40a95c440e2e7be506c1a4fac8da0 to your computer and use it in GitHub Desktop.
Tab bar custom badge swift
This file contains hidden or 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
GeometryReader { geometry in | |
ZStack(alignment: .bottomLeading) { | |
// TabView | |
TabView(selection: $selectedTab) { | |
Text("First View") | |
.padding() | |
.tabItem { | |
Label("Menu", systemImage: "list.dash") | |
}.tag(0) | |
Text("Second View") | |
.tabItem { | |
Label("Order", systemImage: "square.and.pencil") | |
}.tag(1) | |
Text("Sleep View") | |
.tabItem { | |
Label("Phinoz", systemImage: "square.and.pencil") | |
}.tag(2) | |
Text("Phinoz View") | |
.tabItem { | |
Label("Phinoz", systemImage: "square.and.pencil") | |
}.tag(3) | |
} | |
// Badge View | |
ZStack { | |
Circle() | |
.foregroundColor(.red) | |
} | |
.frame(width: 12) | |
.offset(x: ((2 * CGFloat(self.badgePosition)) - 1) * (geometry.size.width / (1.8 * self.tabsCount)), y: UIDevice.current.orientation.isLandscape ? -20 : -29) | |
// .opacity(self.badgeNumber == 0 ? 0 : 1) | |
} | |
}.ignoresSafeArea(.keyboard) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment