Swiftpack.co - kieranb662/SegmentedPicker as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by kieranb662.
kieranb662/SegmentedPicker 0.0.2
SwiftUI Segmented Picker. Create vertical and horizontal pickers and style them to your liking
⭐️ 14
🕓 1 year ago
.package(url: "https://github.com/kieranb662/SegmentedPicker.git", from: "0.0.2")

Segmented Picker Logo

SwiftUI Swift 5.1 Swift 5.1 kieranb662 followers

Segmented Picker Example Gif

Use the SegmentedPicker library to create custom vertical or horizontal SegmentedPickers. Follow along with the examples below to get started quickly.

import SwiftUI
import SegmentedPicker
import Shapes

struct LineCapPicker: View {
    @State var lineCap: LineCap = .butt
    enum LineCap: String, CaseIterable, Identifiable {
        case butt = "butt"
        case round = "round"
        case square = "square"
        var id: String { self.rawValue }
        var cgLineCap: CGLineCap {
            switch self {
            case .butt:
                return .butt
            case .round:
                return .round
            case .square:
                return .square
    var body: some View {
        SegmentedPicker($lineCap, LineCap.allCases, isVertical: true) { (cap: LineCap)   in
                .stroke(Color(white: 0.85), style: StrokeStyle(lineWidth: 20, lineCap: cap.cgLineCap))
                .frame(width: 40)
        }.overlay(RoundedRectangle(cornerRadius: 5).stroke(Color.green))
            .frame(height: 120)

struct RGBColorSpacePicker: View {
    let colorSpaces: [String] = ["sRGB", "sRGB Linear", "Display P3"]
    @State var selected: String = "sRGB"
    var body: some View {
        SegmentedPicker($selected, colorSpaces) { (text: String)   in
        }.overlay(RoundedRectangle(cornerRadius: 5).stroke(Color.green))

struct TextAlignmentPicker: View {
    @State var alignment: TextAlignmentEnum = .left
    enum TextAlignmentEnum: String, CaseIterable, Identifiable {
        case left = "text.alignleft"
        case center = "text.aligncenter"
        case right = "text.alignright"
        var id: String {rawValue}
        var alignment: TextAlignment {
            switch self {
            case .left:
                return .leading
            case .center:
                return .center
            case .right:
                return .trailing
    var body: some View {
        SegmentedPicker($alignment, TextAlignmentEnum.allCases) { (alignment)   in
            Image(systemName: alignment.rawValue)
        }.overlay(RoundedRectangle(cornerRadius: 5).stroke(Color.green))

struct SegmentedPickerExample: View {
    var body: some View {
        ZStack {
            Color(white: 0.1)
            VStack {
                Text("RGB Color Space").padding()
                Text("Text Alignment").padding()
                Text("Line Cap").padding()
        }.navigationBarTitle("Segmented Picker")

struct ContentView: View {
    var body: some View {

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {


Stars: 14
Last commit: 1 year ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

Added platforms for archive builds
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics