Coder Social home page Coder Social logo

shima11 / pincodeinputview Goto Github PK

View Code? Open in Web Editor NEW
154.0 5.0 22.0 2.88 MB

A input text view for entering pin code.

License: MIT License

Swift 88.29% Ruby 7.69% Objective-C 4.02%
pincode inputview textview caret cursor uitextview uitextfield itemview carthage cocoapods

pincodeinputview's Introduction

PinCodeInputView

A text input view for entering pin code.

Features

  • something...

Getting Started

View Hierarchy

SurfaceView is used to detect a user gesture. ItemView is Appearance. You can customize ItemView.

private class ContainerItemView<T: UIView & ItemType>: UIView {
    var itemView: T
    private let surfaceView: UIView = .init()
    private var didTapHandler: (() -> ())?
}

To create your customize ItemView, you create a view conforming to ItemType.

public protocol ItemType {
    var text: Character? { get set }
    var isHiddenCursor: Bool { get set }
    func set(appearance: Appearance)
}

About to set appearance.

public struct Appearance { }

pinCodeInputView.set(appearance: )

Usage

import PinCodeInputView

standard

// initialize
let pinCodeInputView: PinCodeInputView<ItemView> = .init(
    digit: 6,
    itemSpacing: 8,
    itemFactory: {
    return ItemView()
})

view.addSubview(pinCodeInputView)

// set appearance
pinCodeInputView.set(
    appearance: .init(
        itemSize: .init(width: 44, height: 68),
        font: .systemFont(ofSize: 28, weight: .bold),
        textColor: .white,
        backgroundColor: .darkGray,
        cursorColor: .blue,
        cornerRadius: 8
    )
)

// text handling
pinCodeInputView.set(changeTextHandler: { text in
    print(text)
})

customize

final class CustomItemView: UIView, ItemType {
    var text: Character?
    var isHiddenCursor: Bool
    func set(appearance: Appearance) {}
    
    // ...
}

let pinCodeInputView: PinCodeInputView<CustomItemView> = .init(
    digit: 6,
    itemSpacing: 8,
    itemFactory: {
    return CustomItemView()
})

Installation

Carthage

For Installing with Carthage, and add it to your Cartfile.

github "shima11/PinCodeInputView"
$ carthage update

CocoaPods

For installing with CocoaPods, and add it to your Podfile.

pod "PinCodeInputView"
$ pod update

License

Licence MIT

pincodeinputview's People

Contributors

jrosen081 avatar shima11 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pincodeinputview's Issues

UITextTrait does not support iOS 13 AutoFill textContentType

Leaving a note here for anyone who encounters this in the future. Unfortunately, I don't think it is possible to resolve this issue in PinCodeInpuView codebase without a rewrite.

In order to get iOS 13 AutoFill support, you need to use UITextField or UITextView. Custom views that implement UITextInputTraits—which seems to be how PinCodeInputView is implemented—are not supported for UITextContentType.oneTimeCode.

image

More info is available on Apple's docs and WWWDC @ 22:40.

Thanks!

Dynamic Width

Is there a way to make the input views have a dynamic width?

So let's say I need more than 6 input views in a smaller width. How can I get that to adjust dynamically based on the iPhone screen size?

Use with Storyboard?

Thanks for this great library.

I am having trouble using it with Storyboard. If I do the following:

@IBOutlet var input: PinCodeInputView?

Xcode complains about using a generic type, whereas if I do something like:

@IBOutlet var input: PinCodeInputView<ItemView>?

it doesn't work either (@IBOutlet property cannot have non-'@objc' class type 'PinCodeInputView).

Is there any way to use the library with Storyboard? Thanks!

Layout constraint conflict

This is from running the demo project:

2019-06-19 23:35:59.883540+0800 Demo[91228:19194565] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600001a05a90 'UISV-canvas-connection' UIStackView:0x7fb4d1903cc0.leading == _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310.leading   (active)>",
    "<NSLayoutConstraint:0x600001a04b40 'UISV-canvas-connection' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404098c0]-(0)-|   (active, names: '|':UIStackView:0x7fb4d1903cc0 )>",
    "<NSLayoutConstraint:0x600001a05db0 'UISV-fill-equally' _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540406670.width == _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310.width   (active)>",
    "<NSLayoutConstraint:0x600001a06580 'UISV-fill-equally' _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540407490.width == _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310.width   (active)>",
    "<NSLayoutConstraint:0x600001a05cc0 'UISV-fill-equally' _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404080a0.width == _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310.width   (active)>",
    "<NSLayoutConstraint:0x600001a06670 'UISV-fill-equally' _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540408cb0.width == _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310.width   (active)>",
    "<NSLayoutConstraint:0x600001a067b0 'UISV-fill-equally' _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404098c0.width == _TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310.width   (active)>",
    "<NSLayoutConstraint:0x600001a05c70 'UISV-spacing' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540405310]-(8)-[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540406670]   (active)>",
    "<NSLayoutConstraint:0x600001a063a0 'UISV-spacing' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540406670]-(8)-[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540407490]   (active)>",
    "<NSLayoutConstraint:0x600001a065d0 'UISV-spacing' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540407490]-(8)-[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404080a0]   (active)>",
    "<NSLayoutConstraint:0x600001a06620 'UISV-spacing' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404080a0]-(8)-[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540408cb0]   (active)>",
    "<NSLayoutConstraint:0x600001a066c0 'UISV-spacing' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540408cb0]-(8)-[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404098c0]   (active)>",
    "<NSLayoutConstraint:0x600001a000f0 'UIView-Encapsulated-Layout-Width' UIStackView:0x7fb4d1903cc0.width == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001a066c0 'UISV-spacing' H:[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb540408cb0]-(8)-[_TtGCGC16PinCodeInputView16PinCodeInputViewCS_8ItemView_P10$100d482f017ContainerItemViewS1__S1__:0x7fb5404098c0]   (active)>

Can't find keyplane that supports type 4 for keyboard

I'm getting the following error when running it on a physical device:

2019-06-19 22:57:08.645751 [20946:5011500] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 20603_PortraitChoco_iPhone-Simple-Pad_Default

While it's normal to see it on a simulator (no such keypad on Mac), I'm not sure why I'm seeing it on a phone. I'm on an iPhone X.

Pods not functioning properly

Hi there, thank you for this library. There is an issue with Pods of the library, when library is imported manually it works fine otherwise if installed through Pods, it fails to recognise ItemView & ItemType. Please provide insight or a fix. Thanks.

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.