Coder Social home page Coder Social logo

swiftuiwheelpicker's Introduction

SwiftUIWheelPicker

Version License Platform

Horizontal wheel picker for SwiftUI

Requirements

iOS 13.0+

Installation

pod 'SwiftUIWheelPicker'

Import

import SwiftUIWheelPicker

Getting Started

Basic use

Basic Use

@State var indexBasic: Int = 5
@State var items: [Int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

...

SwiftUIWheelPicker($indexBasic, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
    }
}
.frame(width: geometry.size.width - 40, height: 40, alignment: .center)
.padding(.top, 10)

With Visible Count

With Visible Count

SwiftUIWheelPicker($indexRatio, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
    }
}
.width(.Ratio(0.1))
public enum WidthOption {
    case VisibleCount(Int) // How many items to show on the display
    case Fixed(CGFloat) // to a fixed width
    case Ratio(CGFloat) // From the width of the view to the ratio
}

With Alpha

With Alpha

SwiftUIWheelPicker($indexAlpha, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
    }
}
.scrollAlpha(0.1)

With Scale

With Scale

SwiftUIWheelPicker($indexScale, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
    }
}
.scrollScale(0.4)

With Gradient

With Scale

SwiftUIWheelPicker($indexGradient, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
    }
}
.edgeLeft(AnyView(
    LinearGradient(gradient: Gradient(colors: [Color.gray.opacity(0.4), Color.white.opacity(0)]), startPoint: .leading, endPoint: .trailing)
), width: .Ratio(0.2))
.edgeRight(AnyView(
    LinearGradient(gradient: Gradient(colors: [Color.white.opacity(0), Color.gray.opacity(0.4)]), startPoint: .leading, endPoint: .trailing)
), width: .Ratio(0.2))

Center indicator

Center indicator

SwiftUIWheelPicker($indexIndicator, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
    }
}
.centerView(AnyView(
    HStack(alignment: .center, spacing: 0) {
        Divider()
            .frame(width: 1)
            .background(Color.gray)
            .padding(EdgeInsets(top: 6, leading: 0, bottom: 6, trailing: 0))
            .opacity(0.4)
        Spacer()
        Divider()
            .frame(width: 1)
            .background(Color.gray)
            .padding(EdgeInsets(top: 6, leading: 0, bottom: 6, trailing: 0))
            .opacity(0.4)
    }
), width: .Fixed(40))

Selected Value

Selected Value

@State var indexValue: Int = 5
@State var items: [Int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Text("Selected Value : \(indexValue)").font(Font.title)
SwiftUIWheelPicker($indexValue, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
            .background(value % 2 == 0 ? Color.blue.opacity(0.4) : Color.green.opacity(0.4))
    }
}

Scroll To

Scroll To

HStack(alignment: .bottom, spacing: 20) {
    Text("Scroll To ").font(Font.title)
    Spacer()
    Button("First") {
        indexScrollTo = 0
    }
    Button("Center") {
        indexScrollTo = items.count / 2
    }
    Button("Last") {
        indexScrollTo = items.count - 1
    }
}
SwiftUIWheelPicker($indexScrollTo, items: $items) { value in
    GeometryReader { reader in
        Text("\(value)")
            .frame(width: reader.size.width, height: reader.size.height, alignment: .center)
            .background(value % 2 == 0 ? Color.blue.opacity(0.4) : Color.green.opacity(0.4))
    }
}

Author

ggaljjak, [email protected]

License

SwiftUIWheelPicker is available under the MIT license. See the LICENSE file for more info.

swiftuiwheelpicker's People

Contributors

ggjjack avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.