article

Wednesday, March 16, 2022

SwiftUI Sliding Tabs | SlidingTab Package

SwiftUI Sliding Tabs | SlidingTab Package

https://github.com/QuynhNguyen/SlidingTabView

SlidingTabView is a simple Android-Like tab view that is built using the latest and greatest SwiftUI. Almost everything is customizable!



ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
//  ContentView.swift
//  SwiftUIProject
//
//  Created by Cairocoders
//
 
import SwiftUI
import SlidingTabView
 
struct ContentView: View {
    @State private var tabIndex = 0
     
    var body: some View {
        VStack {
            SlidingTabView(selection: $tabIndex, tabs: ["Home", "Friends", "Settings"], animation: .easeInOut)
            Spacer()
             
            if tabIndex == 0 {
                TabAView()
            } else if tabIndex == 1 {
                TabBView()
            } else if tabIndex == 2 {
                TabCView()
            }
            Spacer()
        }
    }
}
 
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
 
struct TabAView: View {
    var body: some View {
        VStack {
            Image("1")
                .resizable()
            Text("Tab Home")
                .font(.title)
        }
    }
}
 
struct TabBView: View {
    var body: some View {
        VStack {
            Image("2")
                .resizable()
            Text("Tab Friends")
                .font(.title)
        }
    }
}
 
struct TabCView: View {
    var body: some View {
        VStack {
            Image("3")
                .resizable()
            Text("Tab Setting")
                .font(.title)
        }
    }
}

Related Post