Skip to content

KazaiMazai/SwiftySegmentedPicker

Repository files navigation

Swifty Segmented Picker

Continuous Integration

Custom segmented picker for SwiftUI.

Installation

Swift Package Manager.

SwiftySegmentedPicker is available through Swift Package Manager. To install it, in Xcode 11.0 or later select File > Swift Packages > Add Package Dependency...

and add SwiftySegmentedPicker repository URL:

https://github.com/KazaiMazai/SwiftySegmentedPicker.git

Underline Selection Usage Example

struct SegmentedPickerExample: View {
    let titles: [String]
    @State var selectedIndex: Int?

    var body: some View {
        SegmentedPicker(
            titles,
            selectedIndex: Binding(
                get: { selectedIndex },
                set: { selectedIndex = $0 }),
            selectionAlignment: .bottom,
            content: { item, isSelected in
                Text(item)
                    .foregroundColor(isSelected ? Color.black : Color.gray )
                    .padding(.horizontal, 16)
                    .padding(.vertical, 8)
            },
            selection: {
                VStack(spacing: 0) {
                    Spacer()
                    Color.black.frame(height: 1)
                }
            })
            .onAppear {
                selectedIndex = 0
            }
            .animation(.easeInOut(duration: 0.3))
    }
}

Capsule Selection Usage Example

struct SegmentedPickerExample: View {
    let titles: [String]
    @State var selectedIndex: Int?

    var body: some View {
        SegmentedPicker(
            titles,
            selectedIndex: Binding(
                get: { selectedIndex },
                set: { selectedIndex = $0 }),
            content: { item, isSelected in
                Text(item)
                    .foregroundColor(isSelected ? Color.white : Color.gray )
                    .padding(.horizontal, 16)
                    .padding(.vertical, 8)
            },
            selection: {
                Capsule()
                    .fill(Color.gray)
            })
            .onAppear {
                selectedIndex = 0
            }
            .animation(.easeInOut(duration: 0.3))
    }
}

Licensing

SwiftySegmentedPicker is licensed under MIT license.

About

Custom segmented picker for SwiftUI

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages