0

I'm developing an app on IOS 15.5 (Xcode 13.4.1) and I want to make a tab bar with this look: Goal bar

But, I can't make that purple box in the selected item like in the image, and it looks like this: Current bar

How can I get that purple box?

This is the code I'm using for this:

import SwiftUI

var tabcolor = Color(red: 120/255, green: 57/255, blue: 62/255)

struct VistaMain: View {
    @EnvironmentObject var vm: ViewModel
    @State var seleccion : Int = 0
    
    var colorSeleccion: Color = Color(red: 73 / 255, green: 82 / 255, blue: 189 / 255)
    
    init(){
        UITabBar.appearance().barTintColor  = UIColor(red: 56/255, green: 57/255, blue: 62/255, alpha: 0)
        UITabBar.appearance().backgroundColor  = UIColor(red: 56/255, green: 57/255, blue: 62/255, alpha: 1)
    }
    
    var body: some View {
        //InicioView()
        Color(red: 48 / 255, green: 49 / 255, blue: 54 / 255)
            .ignoresSafeArea()
            .overlay(
        TabView(selection: $seleccion){
            NuevoExperimentoView()
                .tabItem{
                    Label("Nuevo exp", systemImage: "list.bullet.rectangle.portrait")//.background( frame(width: 30, height: 30))
                }
                .tag(0)
            NuevoExperimentoView()
                .tabItem{
                    Label("Nuevo exp", systemImage: "list.bullet.rectangle.portrait")
                }
                .tag(1)
            NuevoExperimentoView()
                .tabItem{
                    Label("Nuevo exp", systemImage: "list.bullet.rectangle.portrait")
                }
                .tag(2)

            VistaPerfilUsuario(usuarioCurrent: vm.usuariosArray[0], foto: UIImage(data: vm.usuariosArray[0].foto!)!).environmentObject(ViewModel())
                .tabItem{
                    Label("Perfil", systemImage: "person.circle.fill")
                }
                .tag(4)
        }
        )
    }
}

Is it possible on that iOS version?

Dox
  • 99
  • 1
  • 11
  • Please see this answer [here](https://stackoverflow.com/questions/29045147/set-background-color-of-active-tab-bar-item-in-swift). – griv Dec 27 '22 at 17:29
  • it doesn't work for me, saw it before but it seems that something changed on swift 5 and doesn't work anymore like that – Dox Dec 27 '22 at 21:22
  • no, I'm trying to do it without Storyboards because it just "swipes" the entire view instead of doing that change (as far as I know) – Dox Jan 10 '23 at 17:30

0 Answers0