Home > Blockchain >  How to add names to images on tab bar swift
How to add names to images on tab bar swift

Time:11-09

I want to add names bellow the sf symbols, like home, menu, add new:

enter image description here

Like in this picture:

enter image description here

This is the code, using a vm machine and cant copy the code:

enter image description here

CodePudding user response:

You could do it like this but that is not a tab bar, here is an example on how you can do it your way, basically you would add another array with the names for the tabs and wrap the Image and the Text into a VStack:

let tabNames = ["Profile", "Settings", etc...]

HStack {
    ForEach(0..<5, id: \.self) { number in
        Spacer()
        Button(action: {
            self.selectedIndex = number
        }, label: {
            VStack(spacing: 0) {
                Image(systemName: icons[number])
                    .font(.system(size: 25, weight: .regular, design: .default))
                    .foregroundColor(selectedIndex == number ? .black : Color(UIColor.lightGray))
                Text(tabNames[number])
                font(.system(size: 25, weight: .regular, design: .default))
                    .foregroundColor(selectedIndex == number ? .black : Color(UIColor.lightGray))
            }
        })
        Spacer()
    }
}
  • Related