All Projects → dreymonde → Placeholders

dreymonde / Placeholders

Licence: mit
🅿️ Define multiple placeholders for UITextField and animate their change

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Placeholders

JDTextField
Animated UITextField enhance UX for the user by giving clarity that they are focused
Stars: ✭ 19 (-90%)
Mutual labels:  uikit, uitextfield
CurrencyText
Currency text field formatter available for UIKit and SwiftUI 💶✏️
Stars: ✭ 124 (-34.74%)
Mutual labels:  uikit, uitextfield
Tweetextfield
Lightweight set of text fields with nice animation and functionality. 🚀 Inspired by https://uimovement.com/ui/2524/input-field-help/
Stars: ✭ 421 (+121.58%)
Mutual labels:  uikit, uitextfield
Notus Svelte
Notus Svelte: Free Tailwind CSS UI Kit and Admin
Stars: ✭ 144 (-24.21%)
Mutual labels:  uikit
Tangerine
Swift µframework for fetching images 🍊
Stars: ✭ 149 (-21.58%)
Mutual labels:  uikit
Collectionviewslantedlayout
A CollectionView Layout displaying a slanted cells
Stars: ✭ 2,029 (+967.89%)
Mutual labels:  uikit
Render
UIKit a-là SwiftUI.framework [min deployment target iOS10]
Stars: ✭ 2,150 (+1031.58%)
Mutual labels:  uikit
Hana Ui
🌻A react UIKit with nijigen style.
Stars: ✭ 144 (-24.21%)
Mutual labels:  uikit
Light dark toggle
An awesome flutter app which artistically animates light and dark mode 😍
Stars: ✭ 175 (-7.89%)
Mutual labels:  uikit
Crosswindow
💻📱 A cross platform system abstraction library written in C++ for managing windows and performing OS tasks.
Stars: ✭ 155 (-18.42%)
Mutual labels:  uikit
Uiadmin
UIAdmin - UI Kit 3 Responsive Admin Panel
Stars: ✭ 155 (-18.42%)
Mutual labels:  uikit
Mhsoftui
Extension for Neumorphic Soft UI effect in Swift
Stars: ✭ 151 (-20.53%)
Mutual labels:  uikit
Upcomingmovies
Movies app written in Swift 5 using the TMDb API and demonstrating Clean Architecture, Dependency Injection, MVVM and Coordinators.
Stars: ✭ 160 (-15.79%)
Mutual labels:  uikit
Tjpyingke
仿写映客直播,目前已完成部分功能,后续会继续完善 ----[最新添加礼物列表及礼物动画]
Stars: ✭ 146 (-23.16%)
Mutual labels:  uikit
Vue Material Admin
A vue material design admin template
Stars: ✭ 2,170 (+1042.11%)
Mutual labels:  uikit
Dckit
Set of iOS controls with useful IBInspectable properties. Written on Swift.
Stars: ✭ 144 (-24.21%)
Mutual labels:  uikit
Tosegmentedcontrol
A segmented control in the style of iOS 13 compatible with previous versions of iOS.
Stars: ✭ 174 (-8.42%)
Mutual labels:  uikit
Notus Nextjs
Notus NextJS: Free Tailwind CSS UI Kit and Admin
Stars: ✭ 152 (-20%)
Mutual labels:  uikit
Calendar Ios
Calendar View
Stars: ✭ 154 (-18.95%)
Mutual labels:  uikit
Underlinetextfield
Simple UITextfield Subclass with state
Stars: ✭ 156 (-17.89%)
Mutual labels:  uitextfield

Placeholders

Swift Platform

Placeholders gives you the ability to define multiple placeholders for UITextField, and also animate their change in the way you like. The result looks like that:

Demo

You can read more about the library on Medium.

Usage

1. Define a Placeholder object in your view controller:

let placeholders = Placeholders(placeholders: ["First", "Second", "Third"])

If you want to loop placeholders (make the set infinite):

let placeholders = Placeholders(placeholders: ["First", "Second", "Third"], options: .infinite)

If you also want to show them in a random order:

let placeholders = Placeholders(placeholders: ["First", "Second", "Third"], options: [.infinite, .shuffle])

2. In your viewWillAppear method, call .start:

placeholders.start(interval: 3.0,
                   fireInitial: true,
                   textField: textField,
                   animation: .pushTransition(.fromBottom))

That's it!

Advanced

While being easy-to-use, Placeholders can be highly customized. At it's core, Placeholders object doesn't know anything about UITextField. You can easily use it for other purposes if you wish:

let placeholders = Placeholders(placeholders: ["A", "B", "C"], options: .infinite)
placeholders.start(interval: 2.0, fireInitial: true, action: { next in
    print(next)
})

Actually, the UITextField convenience is just a wrapper around this method.

But if you just want to make a custom animation as, for example, .pushTransition, you can extend UITextField.PlaceholderChange. Here is how you can implement your own custom fade animation:

extension UITextField.PlaceholderChange {
    
    static var fade: UITextField.PlaceholderChange<Placeholder> {
        return UITextField.PlaceholderChange { (placeholder, textField) in
            let transition = CATransition()
            transition.duration = 0.35
            transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            transition.type = kCATransitionFade
            textField.subviews.first(where: { NSStringFromClass(type(of: $0)) == "UITextFieldLabel" })?.layer.add(transition, forKey: nil)
            placeholder.set(on: textField)
        }
    }
    
}

This generic Placeholder type and placeholder.set(on: textField) syntax exists in order to support NSAttributedString as a placeholder.

You can also use convenience .caTransition static function to make your life a bit easier:

extension UITextField.PlaceholderChange {
    
    static var fade: UITextField.PlaceholderChange<Placeholder> {
        return .caTransition {
            let transition = CATransition()
            transition.duration = 0.35
            transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            transition.type = kCATransitionFade
            return transition
        }
    }
    
}

And now you can simply write:

placeholders.start(interval: 3.0,
                   fireInitial: true,
                   textField: textField,
                   animation: .fade)

Neat!

Installation

Placeholders is available through Carthage. To install, just write into your Cartfile:

github "dreymonde/Placeholders" ~> 0.1.0

We also encourage you to write your very own implementation that fits your needs best. Our source code is there to help.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].