How to change the view with TabBar but with a Button (like in Apple Music)

Viewed 41

Hello StackOverflow Users, I am learning SwiftUI and have now a problem.

I want to implement the function like in Apple Music, where you can select between "Apple Music" and "Your Library" (Look at the Picture) (It's change the List when you click on "Your Library"/"Deine Mediathek")

It's like the TabBar, but I don't know what is called. So maybe someone here can help me…

I am from germany, so sorry for my bad english. Hope someone could understand it. Reference Picture from Apple Music

1 Answers

That would be the Picker:

    import SwiftUI

enum PickerItems: String {
    case item1
    case item2
}

struct pickerView: View {
    @State var selected: PickerItems = .item1
    var body: some View {
        
        VStack{
        Picker("type", selection: $selected) {

            Text("OPTION 1").tag(PickerItems.item1)
            Text("OPTION 2").tag(PickerItems.item2)
           
        }.pickerStyle(.segmented)
         
            Text("Selected View: \(selected.rawValue)")
            
            
        }
    }
}

enter image description here

Related