I want to customize the tab bar like the curved rectangle in the center but all i am able to do is added one image in the center. the border should come below the circle, tried so many ways but it didn't worked, hope someone would help me to get this.
Here I have tried:
What I am expecting:
TabBarView:
struct TabBarView: View {
@State var selectedTab = 0
var body: some View {
ZStack(alignment: .bottom) {
TabView(selection: $selectedTab) {
HomeView()
.tag(0)
Search()
.tag(1)
Tickets()
.tag(2)
Profile()
.tag(3)
Settings()
.tag(4)
}
RoundedRectangle(cornerRadius: 25)
.frame(width: 350, height: 70)
.foregroundColor(.white)
.shadow(radius: 0.8)
Button {
selectedTab = 2
} label: {
CustomTabItem(imageName: "ticket", title: "Ticket", isActive: (selectedTab == 2))
}
.frame(width: 65, height: 65)
.background(Color.white)
.clipShape(Circle())
.shadow(radius: 0.8)
.offset(y: -50)
HStack {
ForEach(TabbedItems.allCases, id: \.self) { item in
if item != .ticket { // Exclude the center button
Button {
selectedTab = item.rawValue
} label: {
CustomTabItem(imageName: item.iconName, title: item.title, isActive: (selectedTab == item.rawValue))
}
}
}
}
.frame(height: 70)
}
}
}
Extension:
extension TabBarView {
func CustomTabItem(imageName: String, title: String, isActive: Bool) -> some View{
HStack(alignment: .center,spacing: 22){
Spacer()
Image(imageName)
.resizable()
.renderingMode(.template)
.foregroundColor(isActive ? .purple : .gray)
.frame(width: 25, height: 25)
Spacer()
}
}
}


You can do it by creating a
Shapewith the required form. I had a go, here's something that's close:Then you can use the custom shape in place of the
RoundedRectanglethat you were using before:Here's how it looks, you'll probably want to tweak the inset a bit more: